Skip to content

Commit 4cdaee2

Browse files
committed
Challenge 2.
jdk 12 used
1 parent 6a450e2 commit 4cdaee2

2 files changed

Lines changed: 44 additions & 2 deletions

File tree

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
<groupId>org.apache.maven.plugins</groupId>
1414
<artifactId>maven-compiler-plugin</artifactId>
1515
<configuration>
16-
<source>8</source>
17-
<target>8</target>
16+
<source>12</source>
17+
<target>12</target>
1818
</configuration>
1919
</plugin>
2020
</plugins>

src/main/java/Challenge_2.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import java.util.function.Function;
2+
3+
/**
4+
* In this Challenge, We learn:
5+
* * String.join() method: String message = String.join("-", "Java", "is", "cool");
6+
* message = "Java-is-cool";
7+
* * Function<String, String> function ----> function.apply() : given an argument of type String the function
8+
* return a String.
9+
* * the overridden method in a anonymous class could be called only if we reference the object:
10+
* new Jedi(){
11+
* overriddenMethod(){...}
12+
* };
13+
* the above method will be never used, unless we write
14+
* new Jedi(){
15+
* overriddenMethod(){...}
16+
* }.overriddenMethod();
17+
*
18+
*/
19+
public class Challenge_2 {
20+
21+
interface Jedi{
22+
String MASTER = "Yoda";
23+
24+
//default String attack(){return jump(jedi-> String.join(jedi, useSaber(), useForce())); }
25+
default String attack(){
26+
return jump(stringInput-> String.join(stringInput, useSaber(), this.useForce()));
27+
}
28+
29+
private String jump( Function<String, String> function){
30+
return function.apply("Luke");
31+
}
32+
33+
private static String useSaber(){return "S";}
34+
35+
private String useForce(){return "F";}
36+
}
37+
38+
public static void main( String[] args ) {
39+
System.out.println(new Jedi(){
40+
public String useForce(){return "X";}}.attack()+ Jedi.useSaber() + Jedi.MASTER);
41+
}
42+
}

0 commit comments

Comments
 (0)