Skip to content

Commit

Permalink
Day 3 break 3
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonHGR committed May 10, 2023
1 parent eac32a2 commit 4df0e2a
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 3 deletions.
32 changes: 32 additions & 0 deletions Questions.txt
Original file line number Diff line number Diff line change
Expand Up @@ -630,3 +630,35 @@ B) Consumer<String> cs = s -> { System.out.println(s); };
C) Supplier<String> ss = (s1, s2) -> s1 + s2;
D) BiPredicate<String> bps = (String s) -> { return s.length() > 0; };
E) ToIntFunction<String> tofs = s -> s.length();

Q) Given:
???? (s, t) -> s.length() - t.length();

Which are correct inserted in place of ????
A) BiFunction<String, String, Integer> f =
B) BiPredicate<String> f =
C) Comparator<String> f =
D) Supplier<String, Integer> f =
E) BinaryOperator<String> f =

Q) Given, in a single file X.java:
interface ArbInter {}
final class Y implements X {}
sealed interface X /* point x */{}
// line n1

Which is/are true?
A) the code compiles as it stands
B) the code compiles if the following is added at point x
permits Y, Z
AND this is added at line 1
class Z implements X {}
C) the code compiles if the following is added at point x
permits Y, Z
AND this is added at line 1
record Z(String name) implements X {}
D) the code compiles if the following is added at point x
permits Y extends ArbInter
E) the code compiles if the following is added at line n1
non-sealed abstract class Z implements X permits Q {}
final class Q extends Z {}
10 changes: 10 additions & 0 deletions src/main/java/doublestuff/Parsing.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package doublestuff;

public class Parsing {
public static void main(String[] args) {
System.out.println(Double.parseDouble("Infinity"));
System.out.println(Double.parseDouble("-Infinity"));
System.out.println(Double.parseDouble("+Infinity"));
System.out.println(Double.parseDouble("NaN"));
}
}
44 changes: 41 additions & 3 deletions src/main/java/lambdas/Demos.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package lambdas;

import java.util.Comparator;
import java.util.List;
import java.util.function.ToIntFunction;
import java.util.function.*;

interface StudentCriterion {
boolean test(Student s);
}

class Student {
public int getGpa() { return 0; }
public List<String> getCourses() { return null; }
public int getGpa() {
return 0;
}

public List<String> getCourses() {
return null;
}
}

class SmartStudent implements StudentCriterion {
Expand Down Expand Up @@ -72,5 +78,37 @@ public static void main(String[] args) {
// Long lng = 99; // Nope
Byte b = null;
long lng = b;

Object BiPredicate;
// BiFunction<String, String, Integer> f = (s, t) -> s.length() - t.length();
// BiPredicate<String> f = (s, t) -> s.length() - t.length();
// Comparator<String> f = (s, t) -> s.length() - t.length();
// Supplier<String, Integer> f = (s, t) -> s.length() - t.length();
BinaryOperator<String> f = (s, t) -> (s.length() - t.length()) + "";
// BinaryOperator<String> f = (s, t) -> s + t;

// IntFunction<Integer> f1 = (f) -> f;
// f1.applyAsInt(Integer.valueOf(0));
}

interface BiFunction<A1, A2, R> {
R apply(A1 a1, A2 a2);
}

interface IntFunction<E> {
E applyAsInt(int i);
}
class MyIntFunction implements IntFunction<Integer> {
@Override
// public Integer applyAsInt(Integer f) {
public Integer applyAsInt(int f) {
// return Integer.valueOf(f);
return f;
}
@Override
// public boolean equals(MyIntFunction me) { return false; }
public boolean equals(Object me) { return false; }


}
}
25 changes: 25 additions & 0 deletions src/main/java/sealedtypes/Ex1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package sealedtypes;

interface Transporter {
}

class Truck implements Transporter {
}

class Car implements Transporter {
}

//class Bicycle implements Transporter {}

public class Ex1 {
public static void main(String[] args) {
Transporter t = Math.random() > 0.5 ? new Truck() : new Car();

if (t instanceof Truck tr) {
// can the truck do this?
} else if (t instanceof Car c) {
// can the car do this?
}

}
}

0 comments on commit 4df0e2a

Please sign in to comment.