SlideShare una empresa de Scribd logo
1 de 78
Descargar para leer sin conexión
whoiam
Developer Advocate @JFrog
@jbaruch on the internetz
whoiam
Solutions Architect @Hazelcast
@gAmUssA on the internetz
@tagir_valeev
1. Two entertaining guys on
stage
2. Funny Puzzling questions
3. You think and vote
4. Official twitter handles:
JAVApuzzlersng
codemash
5. Jfrog.com/shownotes
Watching the puzzlers like… #dafaq
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
Everything works (or doesn't) in the latest Java 8 update
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
Broken Eggs Tale
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
What will be the output?
A.milk/bread/sausage
B.milk/bread/sausage/eggs,don’t forget eggs!
C.milk/bread/sausage/ConcurrentModificationException
D.ConcurrentModificationException
List<String> list = new ArrayList<>();
list.add("milk");
list.add("bread");
list.add("sausage");
Stream<String> stream = list.stream();
list.add("eggs, don’t forget eggs!");
stream.forEach(System.out::println);
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
Late binding,duh…
List<String> list = new ArrayList<>();
list.add("milk");
list.add("bread");
list.add("sausage");
Stream<String> stream = list.stream();
list.add("eggs, don’t forget eggs!");
stream.forEach(System.out::println);
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
Late binding,duh…
List<String> list = new ArrayList<>();
list.add("milk");
list.add("bread");
list.add("sausage");
Stream<String> stream = list.stream();
list.add("eggs, don’t forget eggs!");
stream.forEach(System.out::println);
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
Going Vegan
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
What will be the output?
A.milk/bread/sausage
B.milk/bread/eggs,don’t forget eggs!
C.milk/bread/ConcurrentModificationException
D.ConcurrentModificationException
List<String> list = new ArrayList<>();
list.add("milk");
list.add("bread");
list.add("sausage");
list = list.subList(0, 2); //No sausage, please!
Stream<String> stream = list.stream();
list.add("eggs, don’t forget eggs!");
stream.forEach(System.out::println);
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
Sometimes it’s just a bug…
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
Execute ’em all
What’s the difference between 1 and 2?
A. 1 compiles,2 does not
B. 2 compiles,1 does not
C. Same same,both work fine
D. Same same,both won’t compile
public void killAll(){
ExecutorService ex = Executors.newSingleThreadExecutor();
List<String> sentence = Arrays.asList("Punish");
ex.submit(() -> Files.write(Paths.get("Sentence.txt"), sentence) ); // 1
ex.submit(() -> { Files.write(Paths.get("Sentence.txt"), sentence); }); // 2
}
Semicolons	are	the	evil!
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
What’s the difference between 1 and 2?
A. 1 compiles,2 does not
B. 2 compiles,1 does not
C. Same same,both work fine
D. Same same,both won’t compile
public void killAll(){
ExecutorService ex = Executors.newSingleThreadExecutor();
List<String> sentence = Arrays.asList("Punish");
ex.submit(() -> Files.write(Paths.get("Sentence.txt"), sentence) ); // 1
ex.submit(() -> { Files.write(Paths.get("Sentence.txt"), sentence); }); // 2
}
public void killAll(){
ExecutorService ex = Executors.newSingleThreadExecutor();
List<String> sentence = Arrays.asList("Punish");
ex.submit(() -> Files.write(Paths.get("Sentence.txt"), sentence) ); // 1
ex.submit(() -> { Files.write(Paths.get("Sentence.txt"), sentence); }); // 2
}
@FunctionalInterface
public interface Runnable {
public abstract void run();
}
@FunctionalInterface
public interface Callable<V> {
V call() throws Exception;
}
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
Mad Max
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
How that will work?
A. Compilation error
B. Runtime Exception
C. 3
D. Something else
System.out.println(
Stream.of(-3, -2, -1, 0, 1, 2, 3).max(Math::max).get()
);
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
How about now?
A.−3
B.−1
C.0
D.Something else
System.out.println(
Stream.of(-3, -2, -1, 0, 1, 2, 3).max(Math::max).get()
);
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
How about now?
A.−3
B.−1
C.0
D.Something else
System.out.println(
Stream.of(-3, -2, -1, 0, 1, 2, 3).max(Math::max).get()
);
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
• Math.max(−3,−2) = −2 < 0 à −3 < −2,selecting−2
• Math.max(−2,−1) = −1 < 0 à −2 < −1,selecting−1
• Math.max(−1,0) = 0 à −1 == 0,keeping−1
• Math.max(−1,1) = 1 > 0 à −1 > 1,keeping−1
• Math.max(−1,2) = 2 > 0 à −1 > 2,keeping−1
• Math.max(−1,3) = 3 > 0 à −1 > 3,keeping−1
Stream.of(-3, -2, -1, 0, 1, 2, 3).max(Math::max).get()
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
Let’s upgrade the stack!
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
What will happen?
A. Maps will switch
B. Both will become oldSchool
C. Both will become hipster
D. Really?! That won’t even compile!
Map<String, String> oldSchool = initOldSchoolStack();
// oldSchool = {buildTool=maven, lang=java, db=db2}
Map<String, String> proper = initHipsterStack();
// proper = {buildTool=npm, lang=javascript, db=elastic}
oldSchool.replaceAll(proper::put);
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
void replaceAll(BiFunction<? super K, ? super V, ? extends V> function)
V put(K key, V value);
Map interface
oldSchool.replaceAll(proper::put);
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
void replaceAll(BiFunction<? super K, ? super V, ? extends V> function)
V put(K key, V value);
Map interface
final BiFunction<String, String, String> function =
(key, value) -> proper.put(key, value);
for (Map.Entry<String, String> entry : oldSchool.entrySet())
entry.setValue(function.apply(entry.getKey(), entry.getValue()));
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
void replaceAll(BiFunction<? super K, ? super V, ? extends V> function)
V put(K key, V value);
Map interface
final BiFunction<String, String, String> function =
(key, value) -> proper.put(key, value);
for (Map.Entry<String, String> entry : oldSchool.entrySet())
entry.setValue(function.apply(entry.getKey(), entry.getValue()));
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
How many lines will be the same?
List<String> kitties = Arrays.asList("Soft", "Warm", "Purr");
Comparator<String> kittiesComparator= Comparator.nullsLast(Comparator.naturalOrder());
System.out.println(Collections.max(kitties, kittiesComparator));
System.out.println(kitties.stream().collect(Collectors.maxBy(kittiesComparator)).get());
System.out.println(kitties.stream().max(kittiesComparator).get());
A. All lines the same
B. Two lines the same
C. All different
D. Four different
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
How about now?
List<String> kitties = Arrays.asList("Soft", null, "Purr");
Comparator<String> kittiesComparator= Comparator.nullsLast(Comparator.naturalOrder());
System.out.println(Collections.max(kitties, kittiesComparator));
System.out.println(kitties.stream().collect(Collectors.maxBy(kittiesComparator)).get());
System.out.println(kitties.stream().max(kittiesComparator).get());
A. All lines the same
B. Two lines the same
C. All different
D. Four different
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
How about now?
List<String> kitties = Arrays.asList("Soft", null, "Purr");
Comparator<String> kittiesComparator= Comparator.nullsLast(Comparator.naturalOrder());
System.out.println(Collections.max(kitties, kittiesComparator));
System.out.println(kitties.stream().collect(Collectors.maxBy(kittiesComparator)).get());
System.out.println(kitties.stream().max(kittiesComparator).get());
A. All lines the same
B. Two lines the same
C. All different
D. Four different
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
List<String> kitties = Arrays.asList("Soft", null, "Purr");
Comparator<String> kittiesComparator= Comparator.nullsLast(Comparator.naturalOrder());
System.out.println(Collections.max(kitties, kittiesComparator));
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
List<String> kitties = Arrays.asList("Soft", null, "Purr");
Comparator<String> kittiesComparator= Comparator.nullsLast(Comparator.naturalOrder());
System.out.println(kitties.stream().collect(Collectors.maxBy(kittiesComparator)).get());
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
List<String> kitties = Arrays.asList("Soft", null, "Purr");
Comparator<String> kittiesComparator= Comparator.nullsLast(Comparator.naturalOrder());
System.out.println(kitties.stream().max(kittiesComparator).get());
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
null
Caught: java.lang.NoSuchElementException
Caught: java.lang.NullPointerException
Consistency,yeah.
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
Mutants
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
How to cast to a type without declaring it?
interface Cat{ default void meow() {System.out.println(”meow ");}}
interface Dog{ default void bark() {System.out.println(”woof ");}}
public static void main(String[] args) {
class Dogcatimplements Dog, Cat{}
test(new Dogcat());
}
static void test(Object obj) {
def x = (?)obj;
x.meow ();
x.bark ();
}
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
How to cast to a type without declaring it?
static void test(Object obj) {
// A. Will that work?
Dog& Catx = (Dog& Cat) obj;
x.meow ();
x.bark ();
}
static void test(Object obj) {
// B. Will that work?
((Consumer<? extends Dog& Cat>)(x -> {
x.meow ();
x.bark ();
})).accept((Dog& Cat)obj); }
static void test(Object obj) {
// C. Will that work?
Optional.of((Dog& Cat) obj)
.ifPresent(x -> {
x.meow ();
x.bark ();
});}
// D. You’re two sick bastards.
interface Cat{ default void meow() {System.out.println(”meow");}}
interface Dog{ default void bark() {System.out.println(”woof");}}
public static void main(String[] args) {
class Dogcat implements Dog, Cat{}
test(new Dogcat());
}
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
How to cast to a type without declaring it?
static void test(Object obj) {
// A. Will that work?
Dog & Cat x = (Dog & Cat) obj;
x.meow();
x.bark();
}
static void test(Object obj) {
// B. Will that work?
((Consumer<? extends Dog & Cat>)(x -> {
x.meow();
x.bark();
})).accept((Dog & Cat)obj); }
static void test(Object obj) {
// C. Will that work?
Optional.of((Dog & Cat) obj)
.ifPresent(x -> {
x.meow();
x.bark();
});}
// D. You’re two sick bastards.
interface Cat{ default void meow() {System.out.println(”meow");}}
interface Dog{ default void bark() {System.out.println(”woof");}}
public static void main(String[] args) {
static class Dogcat implements Dog, Cat{}
test(new Dogcat());
}
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
Bill Gates explains how that works
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
static void test(Object obj) {
// C. Will that work?
Optional.of((Dog & Cat) obj)
.ifPresent(x -> {
x.meow();
x.bark();
});}
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
Viktor Gamov and Baruch Sadogursky call customer
service:
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
What will be the output?
1. HOTEL ECHO LIMA LIMA OSCAR/ HOTEL ECHO LIMA LIMA OSCAR
2. HELLO / HOTEL ECHO LIMA LIMA OSCAR
3. HOTEL ECHO LIMA LIMA OSCAR/ HELLO
4. HELLO/HELLO
public class Test {
String str;
void run() {
str = "hello ";
Supplier<String> s1 = str::toUpperCase;
Supplier<String> s2 = () -> str.toUpperCase();
str = "Hotel Echo Lima Lima Oscar ";
System.out.println(s1.get());
System.out.println(s2.get());
}
}
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
What will be the output?
1. HOTEL ECHO LIMA LIMA OSCAR/ HOTEL ECHO LIMA LIMA OSCAR
2. HELLO / HOTEL ECHO LIMA LIMA OSCAR
3. HOTEL ECHO LIMA LIMA OSCAR/ HELLO
4. HELLO/HELLO
public class Test {
String str;
void run() {
str = ”hello";
Supplier<String> s1 = str::toUpperCase;
Supplier<String> s2 = () -> str.toUpperCase();
str = ”Hotel Echo Lima Lima Oscar";
System.out.println(s1.get());
System.out.println(s2.get());
}
}
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
What will happen?
1. ConcurrentModificationException
2. ArrayIndexOutOfBoundsException
3. NullPointerException
4. No exceptions,all good
List<String> list = new ArrayList<>(Arrays.asList("Arnie", "Chuck", "Slay"));
list.stream().forEach(x -> {
if(x.equals("Chuck")) {
list.remove(x);
}
});
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
Java 8 vs Chuck Norris
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
What will happen?
A. ConcurrentModificationException
B. ArrayIndexOutOfBoundsException
C. NullPointerException
D. No exceptions,all good
List<String> list = new ArrayList<>(Arrays.asList("Arnie", "Chuck", "Slay"));
list.stream().forEach(x -> {
if(x.equals("Chuck")) {
list.remove(x);
}
});
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
Here’s why:
stream().forEach() à spliterator().forEachRemaining()
forEachRemaining checks for mod count once,in the end
Removing element adds null to the end of the array:
["Arne", "Chuck", "Slay"] à ["Arne", "Slay", null]
On the last iteration if(null.equals("Chuck")) fails with NPE (didn’t get to
CME)
Use list.removeIf("Chuck"::equals);
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
System.out.println(Optional.of("rtfm").orElseGet(null));
System.out.println(Optional.empty().map(null).orElse("rtfm"));
What will be the output?
A. rtfm / rtfm
B. rtfm / NullPointerException
C. NullPointerException / NullPointerException
D. NullPointerException / rtfm
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
System.out.println(Optional.of("rtfm").orElseGet(null));
System.out.println(Optional.empty().map(null).orElse("rtfm"));
What will be the output?
A. rtfm /rtfm
B. rtfm / NullPointerException
C. NullPointerException / NullPointerException
D. NullPointerException / rtfm
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
Conclusions
@jbaruch								@gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
- Write readable code!
- Comment all the tricks
- Sometimes it’s a bug
- Static code analysis FTW -
intellij IDEA!
- Rtfm
- Don’t abuse lambdas and
streams!
- Trust us, we have much
more where those came
from.
- Puzzlers? Gotchas? Fetal
position inducing behavior?
- puzzlers jfrog.com
Did you like it?
Praise us on twitter and in the
feedback form!
- javapuzzlersng
- gamussa
- Jbaruch
-http://jfrog.com/shownotes
Didn’t like it?
/dev/null

Más contenido relacionado

La actualidad más candente

Web Development with CoffeeScript and Sass
Web Development with CoffeeScript and SassWeb Development with CoffeeScript and Sass
Web Development with CoffeeScript and SassBrian Hogan
 
JDD 2016 - Philippe Charrière - Golo, The Tiny Language That Gives Super Powers
JDD 2016 - Philippe Charrière -  Golo, The Tiny Language That Gives Super PowersJDD 2016 - Philippe Charrière -  Golo, The Tiny Language That Gives Super Powers
JDD 2016 - Philippe Charrière - Golo, The Tiny Language That Gives Super PowersPROIDEA
 
API Pain Points (PHPNE)
API Pain Points (PHPNE)API Pain Points (PHPNE)
API Pain Points (PHPNE)Phil Sturgeon
 
Ruby - Uma Introdução
Ruby - Uma IntroduçãoRuby - Uma Introdução
Ruby - Uma IntroduçãoÍgor Bonadio
 
Perl 6 for Concurrency and Parallel Computing
Perl 6 for Concurrency and Parallel ComputingPerl 6 for Concurrency and Parallel Computing
Perl 6 for Concurrency and Parallel ComputingAndrew Shitov
 
The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving...
The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving...The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving...
The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving...Puppet
 
Swift Summit 2017: Server Swift State of the Union
Swift Summit 2017: Server Swift State of the UnionSwift Summit 2017: Server Swift State of the Union
Swift Summit 2017: Server Swift State of the UnionChris Bailey
 
Celluloid, Celluloid::IO and Friends
Celluloid, Celluloid::IO and FriendsCelluloid, Celluloid::IO and Friends
Celluloid, Celluloid::IO and FriendsMarcelo Pinheiro
 
Celluloid - Beyond Sidekiq
Celluloid - Beyond SidekiqCelluloid - Beyond Sidekiq
Celluloid - Beyond SidekiqMarcelo Pinheiro
 
Tips and tricks for setting up a Play 2 project
Tips and tricks for setting up a Play 2 projectTips and tricks for setting up a Play 2 project
Tips and tricks for setting up a Play 2 projectManuel Bernhardt
 
Testing TYPO3 Applications
Testing TYPO3 ApplicationsTesting TYPO3 Applications
Testing TYPO3 ApplicationsAndré Wuttig
 
Representing Material Culture Online: Historic Clothing in Omeka
Representing Material Culture Online: Historic Clothing in OmekaRepresenting Material Culture Online: Historic Clothing in Omeka
Representing Material Culture Online: Historic Clothing in OmekaArden Kirkland
 
Micropage in microtime using microframework
Micropage in microtime using microframeworkMicropage in microtime using microframework
Micropage in microtime using microframeworkRadek Benkel
 

La actualidad más candente (20)

Web Development with CoffeeScript and Sass
Web Development with CoffeeScript and SassWeb Development with CoffeeScript and Sass
Web Development with CoffeeScript and Sass
 
JDD 2016 - Philippe Charrière - Golo, The Tiny Language That Gives Super Powers
JDD 2016 - Philippe Charrière -  Golo, The Tiny Language That Gives Super PowersJDD 2016 - Philippe Charrière -  Golo, The Tiny Language That Gives Super Powers
JDD 2016 - Philippe Charrière - Golo, The Tiny Language That Gives Super Powers
 
FP in JS-Land
FP in JS-LandFP in JS-Land
FP in JS-Land
 
API Pain Points (PHPNE)
API Pain Points (PHPNE)API Pain Points (PHPNE)
API Pain Points (PHPNE)
 
Api pain points
Api pain pointsApi pain points
Api pain points
 
Ruby - Uma Introdução
Ruby - Uma IntroduçãoRuby - Uma Introdução
Ruby - Uma Introdução
 
Espresso devoxx 2014
Espresso devoxx 2014Espresso devoxx 2014
Espresso devoxx 2014
 
Perl 6 for Concurrency and Parallel Computing
Perl 6 for Concurrency and Parallel ComputingPerl 6 for Concurrency and Parallel Computing
Perl 6 for Concurrency and Parallel Computing
 
CouchDB Day NYC 2017: JSON Documents
CouchDB Day NYC 2017: JSON DocumentsCouchDB Day NYC 2017: JSON Documents
CouchDB Day NYC 2017: JSON Documents
 
The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving...
The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving...The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving...
The Puppet Debugging Kit: Building Blocks for Exploration and Problem Solving...
 
Swift Summit 2017: Server Swift State of the Union
Swift Summit 2017: Server Swift State of the UnionSwift Summit 2017: Server Swift State of the Union
Swift Summit 2017: Server Swift State of the Union
 
CouchDB Day NYC 2017: Mango
CouchDB Day NYC 2017: MangoCouchDB Day NYC 2017: Mango
CouchDB Day NYC 2017: Mango
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
 
Celluloid, Celluloid::IO and Friends
Celluloid, Celluloid::IO and FriendsCelluloid, Celluloid::IO and Friends
Celluloid, Celluloid::IO and Friends
 
Celluloid - Beyond Sidekiq
Celluloid - Beyond SidekiqCelluloid - Beyond Sidekiq
Celluloid - Beyond Sidekiq
 
Tips and tricks for setting up a Play 2 project
Tips and tricks for setting up a Play 2 projectTips and tricks for setting up a Play 2 project
Tips and tricks for setting up a Play 2 project
 
Testing TYPO3 Applications
Testing TYPO3 ApplicationsTesting TYPO3 Applications
Testing TYPO3 Applications
 
Representing Material Culture Online: Historic Clothing in Omeka
Representing Material Culture Online: Historic Clothing in OmekaRepresenting Material Culture Online: Historic Clothing in Omeka
Representing Material Culture Online: Historic Clothing in Omeka
 
Micropage in microtime using microframework
Micropage in microtime using microframeworkMicropage in microtime using microframework
Micropage in microtime using microframework
 
Elegant APIs
Elegant APIsElegant APIs
Elegant APIs
 

Destacado

Patterns and antipatterns in Docker image lifecycle @ Codemash 2017
Patterns and antipatterns in Docker image lifecycle @ Codemash 2017Patterns and antipatterns in Docker image lifecycle @ Codemash 2017
Patterns and antipatterns in Docker image lifecycle @ Codemash 2017Baruch Sadogursky
 
Patterns and antipatterns in Docker image lifecycle @ DevOpsDays Charlotte 2017
Patterns and antipatterns in Docker image lifecycle @ DevOpsDays Charlotte 2017Patterns and antipatterns in Docker image lifecycle @ DevOpsDays Charlotte 2017
Patterns and antipatterns in Docker image lifecycle @ DevOpsDays Charlotte 2017Baruch Sadogursky
 
Sunlight & Air: 10 Lessons for Growing Junior Developers
Sunlight & Air: 10 Lessons for Growing Junior DevelopersSunlight & Air: 10 Lessons for Growing Junior Developers
Sunlight & Air: 10 Lessons for Growing Junior DevelopersErika Carlson
 
Железные счётчики на страже производительности
Железные счётчики на страже производительностиЖелезные счётчики на страже производительности
Железные счётчики на страже производительностиSergey Kuksenko
 
JPoint 2016 - Валеев Тагир - Странности Stream API
JPoint 2016 - Валеев Тагир - Странности Stream APIJPoint 2016 - Валеев Тагир - Странности Stream API
JPoint 2016 - Валеев Тагир - Странности Stream APItvaleev
 
Stream API: рекомендации лучших собаководов
Stream API: рекомендации лучших собаководовStream API: рекомендации лучших собаководов
Stream API: рекомендации лучших собаководовtvaleev
 
"Quantum" Performance Effects
"Quantum" Performance Effects"Quantum" Performance Effects
"Quantum" Performance EffectsSergey Kuksenko
 
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java DevelopersWebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java DevelopersViktor Gamov
 
Functional UI testing of Adobe Flex RIA
Functional UI testing of Adobe Flex RIAFunctional UI testing of Adobe Flex RIA
Functional UI testing of Adobe Flex RIAViktor Gamov
 
JavaOne 2013: «Java and JavaScript - Shaken, Not Stirred»
JavaOne 2013: «Java and JavaScript - Shaken, Not Stirred»JavaOne 2013: «Java and JavaScript - Shaken, Not Stirred»
JavaOne 2013: «Java and JavaScript - Shaken, Not Stirred»Viktor Gamov
 
Creating your own private Download Center with Bintray
Creating your own private Download Center with Bintray Creating your own private Download Center with Bintray
Creating your own private Download Center with Bintray Baruch Sadogursky
 
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code SF...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code SF...DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code SF...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code SF...Baruch Sadogursky
 
Java 8 Puzzlers [as presented at OSCON 2016]
Java 8 Puzzlers [as presented at  OSCON 2016]Java 8 Puzzlers [as presented at  OSCON 2016]
Java 8 Puzzlers [as presented at OSCON 2016]Baruch Sadogursky
 
Spring Data: New approach to persistence
Spring Data: New approach to persistenceSpring Data: New approach to persistence
Spring Data: New approach to persistenceOleksiy Rezchykov
 
Testing Flex RIAs for NJ Flex user group
Testing Flex RIAs for NJ Flex user groupTesting Flex RIAs for NJ Flex user group
Testing Flex RIAs for NJ Flex user groupViktor Gamov
 
Morning at Lohika 2nd anniversary
Morning at Lohika 2nd anniversaryMorning at Lohika 2nd anniversary
Morning at Lohika 2nd anniversaryTaras Matyashovsky
 
Couchbase Sydney meetup #1 Couchbase Architecture and Scalability
Couchbase Sydney meetup #1    Couchbase Architecture and ScalabilityCouchbase Sydney meetup #1    Couchbase Architecture and Scalability
Couchbase Sydney meetup #1 Couchbase Architecture and ScalabilityKarthik Babu Sekar
 

Destacado (20)

Patterns and antipatterns in Docker image lifecycle @ Codemash 2017
Patterns and antipatterns in Docker image lifecycle @ Codemash 2017Patterns and antipatterns in Docker image lifecycle @ Codemash 2017
Patterns and antipatterns in Docker image lifecycle @ Codemash 2017
 
Patterns and antipatterns in Docker image lifecycle @ DevOpsDays Charlotte 2017
Patterns and antipatterns in Docker image lifecycle @ DevOpsDays Charlotte 2017Patterns and antipatterns in Docker image lifecycle @ DevOpsDays Charlotte 2017
Patterns and antipatterns in Docker image lifecycle @ DevOpsDays Charlotte 2017
 
Sunlight & Air: 10 Lessons for Growing Junior Developers
Sunlight & Air: 10 Lessons for Growing Junior DevelopersSunlight & Air: 10 Lessons for Growing Junior Developers
Sunlight & Air: 10 Lessons for Growing Junior Developers
 
JDK8: Stream style
JDK8: Stream styleJDK8: Stream style
JDK8: Stream style
 
Железные счётчики на страже производительности
Железные счётчики на страже производительностиЖелезные счётчики на страже производительности
Железные счётчики на страже производительности
 
JPoint 2016 - Валеев Тагир - Странности Stream API
JPoint 2016 - Валеев Тагир - Странности Stream APIJPoint 2016 - Валеев Тагир - Странности Stream API
JPoint 2016 - Валеев Тагир - Странности Stream API
 
Stream API: рекомендации лучших собаководов
Stream API: рекомендации лучших собаководовStream API: рекомендации лучших собаководов
Stream API: рекомендации лучших собаководов
 
"Quantum" Performance Effects
"Quantum" Performance Effects"Quantum" Performance Effects
"Quantum" Performance Effects
 
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java DevelopersWebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
WebSockets: The Current State of the Most Valuable HTML5 API for Java Developers
 
Functional UI testing of Adobe Flex RIA
Functional UI testing of Adobe Flex RIAFunctional UI testing of Adobe Flex RIA
Functional UI testing of Adobe Flex RIA
 
JavaOne 2013: «Java and JavaScript - Shaken, Not Stirred»
JavaOne 2013: «Java and JavaScript - Shaken, Not Stirred»JavaOne 2013: «Java and JavaScript - Shaken, Not Stirred»
JavaOne 2013: «Java and JavaScript - Shaken, Not Stirred»
 
Creating your own private Download Center with Bintray
Creating your own private Download Center with Bintray Creating your own private Download Center with Bintray
Creating your own private Download Center with Bintray
 
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code SF...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code SF...DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code SF...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code SF...
 
Java 8 Puzzlers [as presented at OSCON 2016]
Java 8 Puzzlers [as presented at  OSCON 2016]Java 8 Puzzlers [as presented at  OSCON 2016]
Java 8 Puzzlers [as presented at OSCON 2016]
 
Spring Data: New approach to persistence
Spring Data: New approach to persistenceSpring Data: New approach to persistence
Spring Data: New approach to persistence
 
Javaland keynote final
Javaland keynote finalJavaland keynote final
Javaland keynote final
 
Testing Flex RIAs for NJ Flex user group
Testing Flex RIAs for NJ Flex user groupTesting Flex RIAs for NJ Flex user group
Testing Flex RIAs for NJ Flex user group
 
Confession of an Engineer
Confession of an EngineerConfession of an Engineer
Confession of an Engineer
 
Morning at Lohika 2nd anniversary
Morning at Lohika 2nd anniversaryMorning at Lohika 2nd anniversary
Morning at Lohika 2nd anniversary
 
Couchbase Sydney meetup #1 Couchbase Architecture and Scalability
Couchbase Sydney meetup #1    Couchbase Architecture and ScalabilityCouchbase Sydney meetup #1    Couchbase Architecture and Scalability
Couchbase Sydney meetup #1 Couchbase Architecture and Scalability
 

Similar a Here are a few ways to cast to a type without declaring it:1. Use a generic type parameter:<T> T cast(Object o) { return (T) o;}2. Use a raw type: Object cast(Object o) { return (Object) o; }3. Reflection:Object cast(Object o, Class<?> type) throws Exception { return type.cast(o);}4. Dynamic proxy: interface Castable { Object cast(Object o);}class CastProxy implements Castable { private Class<?> type; public CastProxy(Class

Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers StealBen Scofield
 
Asynchronous API in Java8, how to use CompletableFuture
Asynchronous API in Java8, how to use CompletableFutureAsynchronous API in Java8, how to use CompletableFuture
Asynchronous API in Java8, how to use CompletableFutureJosé Paumard
 
NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionPaulo Morgado
 
XML-Free Programming
XML-Free ProgrammingXML-Free Programming
XML-Free ProgrammingStephen Chin
 
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013Arun Gupta
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5arajivmordani
 
Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#Paulo Morgado
 
Avinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPressAvinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPresswpnepal
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsKonrad Malawski
 
JSLab. Домников Виталий. "ES6 генераторы и Koa.js"
JSLab. Домников Виталий. "ES6 генераторы и Koa.js"JSLab. Домников Виталий. "ES6 генераторы и Koa.js"
JSLab. Домников Виталий. "ES6 генераторы и Koa.js"GeeksLab Odessa
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentationipolevoy
 
모던자바의 역습
모던자바의 역습모던자바의 역습
모던자바의 역습DoHyun Jung
 
Jersey framework
Jersey frameworkJersey framework
Jersey frameworkknight1128
 
Seven Peaks Speaks - Compose Screenshot Testing Made Easy
Seven Peaks Speaks - Compose Screenshot Testing Made EasySeven Peaks Speaks - Compose Screenshot Testing Made Easy
Seven Peaks Speaks - Compose Screenshot Testing Made EasySeven Peaks Speaks
 

Similar a Here are a few ways to cast to a type without declaring it:1. Use a generic type parameter:<T> T cast(Object o) { return (T) o;}2. Use a raw type: Object cast(Object o) { return (Object) o; }3. Reflection:Object cast(Object o, Class<?> type) throws Exception { return type.cast(o);}4. Dynamic proxy: interface Castable { Object cast(Object o);}class CastProxy implements Castable { private Class<?> type; public CastProxy(Class (20)

Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers Steal
 
Lettering js
Lettering jsLettering js
Lettering js
 
Asynchronous API in Java8, how to use CompletableFuture
Asynchronous API in Java8, how to use CompletableFutureAsynchronous API in Java8, how to use CompletableFuture
Asynchronous API in Java8, how to use CompletableFuture
 
NetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf EditionNetPonto - The Future Of C# - NetConf Edition
NetPonto - The Future Of C# - NetConf Edition
 
XML-Free Programming
XML-Free ProgrammingXML-Free Programming
XML-Free Programming
 
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013
Java EE 7: Whats New in the Java EE Platform @ Devoxx 2013
 
Nantes Jug - Java 7
Nantes Jug - Java 7Nantes Jug - Java 7
Nantes Jug - Java 7
 
The Beauty Of Java Script V5a
The Beauty Of Java Script V5aThe Beauty Of Java Script V5a
The Beauty Of Java Script V5a
 
Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#Tuga IT 2018 Summer Edition - The Future of C#
Tuga IT 2018 Summer Edition - The Future of C#
 
Avinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPressAvinash Kundaliya: Javascript and WordPress
Avinash Kundaliya: Javascript and WordPress
 
Java 8: the good parts!
Java 8: the good parts!Java 8: the good parts!
Java 8: the good parts!
 
JavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good PartsJavaOne 2013: Java 8 - The Good Parts
JavaOne 2013: Java 8 - The Good Parts
 
The Beauty of Java Script
The Beauty of Java ScriptThe Beauty of Java Script
The Beauty of Java Script
 
JSLab. Домников Виталий. "ES6 генераторы и Koa.js"
JSLab. Домников Виталий. "ES6 генераторы и Koa.js"JSLab. Домников Виталий. "ES6 генераторы и Koa.js"
JSLab. Домников Виталий. "ES6 генераторы и Koa.js"
 
Jquery examples
Jquery examplesJquery examples
Jquery examples
 
ActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group PresentationActiveWeb: Chicago Java User Group Presentation
ActiveWeb: Chicago Java User Group Presentation
 
모던자바의 역습
모던자바의 역습모던자바의 역습
모던자바의 역습
 
Es6 hackathon
Es6 hackathonEs6 hackathon
Es6 hackathon
 
Jersey framework
Jersey frameworkJersey framework
Jersey framework
 
Seven Peaks Speaks - Compose Screenshot Testing Made Easy
Seven Peaks Speaks - Compose Screenshot Testing Made EasySeven Peaks Speaks - Compose Screenshot Testing Made Easy
Seven Peaks Speaks - Compose Screenshot Testing Made Easy
 

Más de Baruch Sadogursky

DevOps Patterns & Antipatterns for Continuous Software Updates @ NADOG April ...
DevOps Patterns & Antipatterns for Continuous Software Updates @ NADOG April ...DevOps Patterns & Antipatterns for Continuous Software Updates @ NADOG April ...
DevOps Patterns & Antipatterns for Continuous Software Updates @ NADOG April ...Baruch Sadogursky
 
DevOps Patterns & Antipatterns for Continuous Software Updates @ DevOps.com A...
DevOps Patterns & Antipatterns for Continuous Software Updates @ DevOps.com A...DevOps Patterns & Antipatterns for Continuous Software Updates @ DevOps.com A...
DevOps Patterns & Antipatterns for Continuous Software Updates @ DevOps.com A...Baruch Sadogursky
 
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code NY...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code NY...DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code NY...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code NY...Baruch Sadogursky
 
Data driven devops as presented at QCon London 2018
Data driven devops as presented at QCon London 2018Data driven devops as presented at QCon London 2018
Data driven devops as presented at QCon London 2018Baruch Sadogursky
 
A Research Study Into DevOps Bottlenecks as presented at Oracle Code LA 2018
A Research Study Into DevOps Bottlenecks as presented at Oracle Code LA 2018A Research Study Into DevOps Bottlenecks as presented at Oracle Code LA 2018
A Research Study Into DevOps Bottlenecks as presented at Oracle Code LA 2018Baruch Sadogursky
 
Java Puzzlers NG S03 a DevNexus 2018
Java Puzzlers NG S03 a DevNexus 2018Java Puzzlers NG S03 a DevNexus 2018
Java Puzzlers NG S03 a DevNexus 2018Baruch Sadogursky
 
Where the Helm are your binaries? as presented at Canada Kubernetes Meetups
Where the Helm are your binaries? as presented at Canada Kubernetes MeetupsWhere the Helm are your binaries? as presented at Canada Kubernetes Meetups
Where the Helm are your binaries? as presented at Canada Kubernetes MeetupsBaruch Sadogursky
 
Data driven devops as presented at Codemash 2018
Data driven devops as presented at Codemash 2018Data driven devops as presented at Codemash 2018
Data driven devops as presented at Codemash 2018Baruch Sadogursky
 
A Research Study into DevOps Bottlenecks as presented at Codemash 2018
A Research Study into DevOps Bottlenecks as presented at Codemash 2018A Research Study into DevOps Bottlenecks as presented at Codemash 2018
A Research Study into DevOps Bottlenecks as presented at Codemash 2018Baruch Sadogursky
 
Best Practices for Managing Docker Versions as presented at JavaOne 2017
Best Practices for Managing Docker Versions as presented at JavaOne 2017Best Practices for Managing Docker Versions as presented at JavaOne 2017
Best Practices for Managing Docker Versions as presented at JavaOne 2017Baruch Sadogursky
 
Troubleshooting & Debugging Production Microservices in Kubernetes as present...
Troubleshooting & Debugging Production Microservices in Kubernetes as present...Troubleshooting & Debugging Production Microservices in Kubernetes as present...
Troubleshooting & Debugging Production Microservices in Kubernetes as present...Baruch Sadogursky
 
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Devoxx 2017
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Devoxx 2017DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Devoxx 2017
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Devoxx 2017Baruch Sadogursky
 
Amazon Alexa Skills vs Google Home Actions, the Big Java VUI Faceoff as prese...
Amazon Alexa Skills vs Google Home Actions, the Big Java VUI Faceoff as prese...Amazon Alexa Skills vs Google Home Actions, the Big Java VUI Faceoff as prese...
Amazon Alexa Skills vs Google Home Actions, the Big Java VUI Faceoff as prese...Baruch Sadogursky
 
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Days Be...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Days Be...DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Days Be...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Days Be...Baruch Sadogursky
 
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at The Pittsburgh...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at The Pittsburgh...DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at The Pittsburgh...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at The Pittsburgh...Baruch Sadogursky
 
Let’s Wing It: A Study in DevRel Strategy
 Let’s Wing It: A Study in DevRel Strategy Let’s Wing It: A Study in DevRel Strategy
Let’s Wing It: A Study in DevRel StrategyBaruch Sadogursky
 
Log Driven First Class Customer Support at Scale
Log Driven First Class Customer Support at ScaleLog Driven First Class Customer Support at Scale
Log Driven First Class Customer Support at ScaleBaruch Sadogursky
 
[Webinar] The Frog And The Butler: CI Pipelines For Modern DevOps
[Webinar] The Frog And The Butler: CI Pipelines For Modern DevOps[Webinar] The Frog And The Butler: CI Pipelines For Modern DevOps
[Webinar] The Frog And The Butler: CI Pipelines For Modern DevOpsBaruch Sadogursky
 
Patterns and antipatterns in Docker image lifecycle as was presented at DC Do...
Patterns and antipatterns in Docker image lifecycle as was presented at DC Do...Patterns and antipatterns in Docker image lifecycle as was presented at DC Do...
Patterns and antipatterns in Docker image lifecycle as was presented at DC Do...Baruch Sadogursky
 
Groovy Puzzlers S04: The Bytecode Bites Back at Gr8Conf US 2017
Groovy Puzzlers S04: The Bytecode Bites Back at Gr8Conf US 2017Groovy Puzzlers S04: The Bytecode Bites Back at Gr8Conf US 2017
Groovy Puzzlers S04: The Bytecode Bites Back at Gr8Conf US 2017Baruch Sadogursky
 

Más de Baruch Sadogursky (20)

DevOps Patterns & Antipatterns for Continuous Software Updates @ NADOG April ...
DevOps Patterns & Antipatterns for Continuous Software Updates @ NADOG April ...DevOps Patterns & Antipatterns for Continuous Software Updates @ NADOG April ...
DevOps Patterns & Antipatterns for Continuous Software Updates @ NADOG April ...
 
DevOps Patterns & Antipatterns for Continuous Software Updates @ DevOps.com A...
DevOps Patterns & Antipatterns for Continuous Software Updates @ DevOps.com A...DevOps Patterns & Antipatterns for Continuous Software Updates @ DevOps.com A...
DevOps Patterns & Antipatterns for Continuous Software Updates @ DevOps.com A...
 
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code NY...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code NY...DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code NY...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Oracle Code NY...
 
Data driven devops as presented at QCon London 2018
Data driven devops as presented at QCon London 2018Data driven devops as presented at QCon London 2018
Data driven devops as presented at QCon London 2018
 
A Research Study Into DevOps Bottlenecks as presented at Oracle Code LA 2018
A Research Study Into DevOps Bottlenecks as presented at Oracle Code LA 2018A Research Study Into DevOps Bottlenecks as presented at Oracle Code LA 2018
A Research Study Into DevOps Bottlenecks as presented at Oracle Code LA 2018
 
Java Puzzlers NG S03 a DevNexus 2018
Java Puzzlers NG S03 a DevNexus 2018Java Puzzlers NG S03 a DevNexus 2018
Java Puzzlers NG S03 a DevNexus 2018
 
Where the Helm are your binaries? as presented at Canada Kubernetes Meetups
Where the Helm are your binaries? as presented at Canada Kubernetes MeetupsWhere the Helm are your binaries? as presented at Canada Kubernetes Meetups
Where the Helm are your binaries? as presented at Canada Kubernetes Meetups
 
Data driven devops as presented at Codemash 2018
Data driven devops as presented at Codemash 2018Data driven devops as presented at Codemash 2018
Data driven devops as presented at Codemash 2018
 
A Research Study into DevOps Bottlenecks as presented at Codemash 2018
A Research Study into DevOps Bottlenecks as presented at Codemash 2018A Research Study into DevOps Bottlenecks as presented at Codemash 2018
A Research Study into DevOps Bottlenecks as presented at Codemash 2018
 
Best Practices for Managing Docker Versions as presented at JavaOne 2017
Best Practices for Managing Docker Versions as presented at JavaOne 2017Best Practices for Managing Docker Versions as presented at JavaOne 2017
Best Practices for Managing Docker Versions as presented at JavaOne 2017
 
Troubleshooting & Debugging Production Microservices in Kubernetes as present...
Troubleshooting & Debugging Production Microservices in Kubernetes as present...Troubleshooting & Debugging Production Microservices in Kubernetes as present...
Troubleshooting & Debugging Production Microservices in Kubernetes as present...
 
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Devoxx 2017
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Devoxx 2017DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Devoxx 2017
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at Devoxx 2017
 
Amazon Alexa Skills vs Google Home Actions, the Big Java VUI Faceoff as prese...
Amazon Alexa Skills vs Google Home Actions, the Big Java VUI Faceoff as prese...Amazon Alexa Skills vs Google Home Actions, the Big Java VUI Faceoff as prese...
Amazon Alexa Skills vs Google Home Actions, the Big Java VUI Faceoff as prese...
 
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Days Be...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Days Be...DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Days Be...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at DevOps Days Be...
 
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at The Pittsburgh...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at The Pittsburgh...DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at The Pittsburgh...
DevOps @Scale (Greek Tragedy in 3 Acts) as it was presented at The Pittsburgh...
 
Let’s Wing It: A Study in DevRel Strategy
 Let’s Wing It: A Study in DevRel Strategy Let’s Wing It: A Study in DevRel Strategy
Let’s Wing It: A Study in DevRel Strategy
 
Log Driven First Class Customer Support at Scale
Log Driven First Class Customer Support at ScaleLog Driven First Class Customer Support at Scale
Log Driven First Class Customer Support at Scale
 
[Webinar] The Frog And The Butler: CI Pipelines For Modern DevOps
[Webinar] The Frog And The Butler: CI Pipelines For Modern DevOps[Webinar] The Frog And The Butler: CI Pipelines For Modern DevOps
[Webinar] The Frog And The Butler: CI Pipelines For Modern DevOps
 
Patterns and antipatterns in Docker image lifecycle as was presented at DC Do...
Patterns and antipatterns in Docker image lifecycle as was presented at DC Do...Patterns and antipatterns in Docker image lifecycle as was presented at DC Do...
Patterns and antipatterns in Docker image lifecycle as was presented at DC Do...
 
Groovy Puzzlers S04: The Bytecode Bites Back at Gr8Conf US 2017
Groovy Puzzlers S04: The Bytecode Bites Back at Gr8Conf US 2017Groovy Puzzlers S04: The Bytecode Bites Back at Gr8Conf US 2017
Groovy Puzzlers S04: The Bytecode Bites Back at Gr8Conf US 2017
 

Último

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostZilliz
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsMiki Katsuragi
 

Último (20)

Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage CostLeverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
Leverage Zilliz Serverless - Up to 50X Saving for Your Vector Storage Cost
 
Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Vertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering TipsVertex AI Gemini Prompt Engineering Tips
Vertex AI Gemini Prompt Engineering Tips
 

Here are a few ways to cast to a type without declaring it:1. Use a generic type parameter:<T> T cast(Object o) { return (T) o;}2. Use a raw type: Object cast(Object o) { return (Object) o; }3. Reflection:Object cast(Object o, Class<?> type) throws Exception { return type.cast(o);}4. Dynamic proxy: interface Castable { Object cast(Object o);}class CastProxy implements Castable { private Class<?> type; public CastProxy(Class

  • 1.
  • 4.
  • 6.
  • 7. 1. Two entertaining guys on stage 2. Funny Puzzling questions 3. You think and vote 4. Official twitter handles: JAVApuzzlersng codemash 5. Jfrog.com/shownotes
  • 8.
  • 9. Watching the puzzlers like… #dafaq @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 10. Everything works (or doesn't) in the latest Java 8 update @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 11. @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 12. Broken Eggs Tale @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 13. What will be the output? A.milk/bread/sausage B.milk/bread/sausage/eggs,don’t forget eggs! C.milk/bread/sausage/ConcurrentModificationException D.ConcurrentModificationException List<String> list = new ArrayList<>(); list.add("milk"); list.add("bread"); list.add("sausage"); Stream<String> stream = list.stream(); list.add("eggs, don’t forget eggs!"); stream.forEach(System.out::println);
  • 14. @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 15. Late binding,duh… List<String> list = new ArrayList<>(); list.add("milk"); list.add("bread"); list.add("sausage"); Stream<String> stream = list.stream(); list.add("eggs, don’t forget eggs!"); stream.forEach(System.out::println); @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 16. Late binding,duh… List<String> list = new ArrayList<>(); list.add("milk"); list.add("bread"); list.add("sausage"); Stream<String> stream = list.stream(); list.add("eggs, don’t forget eggs!"); stream.forEach(System.out::println); @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 17. Going Vegan @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 18. What will be the output? A.milk/bread/sausage B.milk/bread/eggs,don’t forget eggs! C.milk/bread/ConcurrentModificationException D.ConcurrentModificationException List<String> list = new ArrayList<>(); list.add("milk"); list.add("bread"); list.add("sausage"); list = list.subList(0, 2); //No sausage, please! Stream<String> stream = list.stream(); list.add("eggs, don’t forget eggs!"); stream.forEach(System.out::println);
  • 19. @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 20. Sometimes it’s just a bug… @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 22. What’s the difference between 1 and 2? A. 1 compiles,2 does not B. 2 compiles,1 does not C. Same same,both work fine D. Same same,both won’t compile public void killAll(){ ExecutorService ex = Executors.newSingleThreadExecutor(); List<String> sentence = Arrays.asList("Punish"); ex.submit(() -> Files.write(Paths.get("Sentence.txt"), sentence) ); // 1 ex.submit(() -> { Files.write(Paths.get("Sentence.txt"), sentence); }); // 2 }
  • 24. What’s the difference between 1 and 2? A. 1 compiles,2 does not B. 2 compiles,1 does not C. Same same,both work fine D. Same same,both won’t compile public void killAll(){ ExecutorService ex = Executors.newSingleThreadExecutor(); List<String> sentence = Arrays.asList("Punish"); ex.submit(() -> Files.write(Paths.get("Sentence.txt"), sentence) ); // 1 ex.submit(() -> { Files.write(Paths.get("Sentence.txt"), sentence); }); // 2 }
  • 25. public void killAll(){ ExecutorService ex = Executors.newSingleThreadExecutor(); List<String> sentence = Arrays.asList("Punish"); ex.submit(() -> Files.write(Paths.get("Sentence.txt"), sentence) ); // 1 ex.submit(() -> { Files.write(Paths.get("Sentence.txt"), sentence); }); // 2 } @FunctionalInterface public interface Runnable { public abstract void run(); } @FunctionalInterface public interface Callable<V> { V call() throws Exception; } @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 26. Mad Max @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 27. How that will work? A. Compilation error B. Runtime Exception C. 3 D. Something else System.out.println( Stream.of(-3, -2, -1, 0, 1, 2, 3).max(Math::max).get() ); @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 28. @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 29. How about now? A.−3 B.−1 C.0 D.Something else System.out.println( Stream.of(-3, -2, -1, 0, 1, 2, 3).max(Math::max).get() ); @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 30. @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 31. How about now? A.−3 B.−1 C.0 D.Something else System.out.println( Stream.of(-3, -2, -1, 0, 1, 2, 3).max(Math::max).get() ); @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 32. • Math.max(−3,−2) = −2 < 0 à −3 < −2,selecting−2 • Math.max(−2,−1) = −1 < 0 à −2 < −1,selecting−1 • Math.max(−1,0) = 0 à −1 == 0,keeping−1 • Math.max(−1,1) = 1 > 0 à −1 > 1,keeping−1 • Math.max(−1,2) = 2 > 0 à −1 > 2,keeping−1 • Math.max(−1,3) = 3 > 0 à −1 > 3,keeping−1 Stream.of(-3, -2, -1, 0, 1, 2, 3).max(Math::max).get() @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 33. Let’s upgrade the stack! @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 34. What will happen? A. Maps will switch B. Both will become oldSchool C. Both will become hipster D. Really?! That won’t even compile! Map<String, String> oldSchool = initOldSchoolStack(); // oldSchool = {buildTool=maven, lang=java, db=db2} Map<String, String> proper = initHipsterStack(); // proper = {buildTool=npm, lang=javascript, db=elastic} oldSchool.replaceAll(proper::put);
  • 35. @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 36. void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) V put(K key, V value); Map interface oldSchool.replaceAll(proper::put); @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 37. void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) V put(K key, V value); Map interface final BiFunction<String, String, String> function = (key, value) -> proper.put(key, value); for (Map.Entry<String, String> entry : oldSchool.entrySet()) entry.setValue(function.apply(entry.getKey(), entry.getValue())); @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 38. void replaceAll(BiFunction<? super K, ? super V, ? extends V> function) V put(K key, V value); Map interface final BiFunction<String, String, String> function = (key, value) -> proper.put(key, value); for (Map.Entry<String, String> entry : oldSchool.entrySet()) entry.setValue(function.apply(entry.getKey(), entry.getValue())); @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 39. @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 40. How many lines will be the same? List<String> kitties = Arrays.asList("Soft", "Warm", "Purr"); Comparator<String> kittiesComparator= Comparator.nullsLast(Comparator.naturalOrder()); System.out.println(Collections.max(kitties, kittiesComparator)); System.out.println(kitties.stream().collect(Collectors.maxBy(kittiesComparator)).get()); System.out.println(kitties.stream().max(kittiesComparator).get()); A. All lines the same B. Two lines the same C. All different D. Four different @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 41. @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 42. How about now? List<String> kitties = Arrays.asList("Soft", null, "Purr"); Comparator<String> kittiesComparator= Comparator.nullsLast(Comparator.naturalOrder()); System.out.println(Collections.max(kitties, kittiesComparator)); System.out.println(kitties.stream().collect(Collectors.maxBy(kittiesComparator)).get()); System.out.println(kitties.stream().max(kittiesComparator).get()); A. All lines the same B. Two lines the same C. All different D. Four different @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 43. @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 44. How about now? List<String> kitties = Arrays.asList("Soft", null, "Purr"); Comparator<String> kittiesComparator= Comparator.nullsLast(Comparator.naturalOrder()); System.out.println(Collections.max(kitties, kittiesComparator)); System.out.println(kitties.stream().collect(Collectors.maxBy(kittiesComparator)).get()); System.out.println(kitties.stream().max(kittiesComparator).get()); A. All lines the same B. Two lines the same C. All different D. Four different @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 45. List<String> kitties = Arrays.asList("Soft", null, "Purr"); Comparator<String> kittiesComparator= Comparator.nullsLast(Comparator.naturalOrder()); System.out.println(Collections.max(kitties, kittiesComparator)); @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 46. List<String> kitties = Arrays.asList("Soft", null, "Purr"); Comparator<String> kittiesComparator= Comparator.nullsLast(Comparator.naturalOrder()); System.out.println(kitties.stream().collect(Collectors.maxBy(kittiesComparator)).get()); @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 47. List<String> kitties = Arrays.asList("Soft", null, "Purr"); Comparator<String> kittiesComparator= Comparator.nullsLast(Comparator.naturalOrder()); System.out.println(kitties.stream().max(kittiesComparator).get()); @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 50. How to cast to a type without declaring it? interface Cat{ default void meow() {System.out.println(”meow ");}} interface Dog{ default void bark() {System.out.println(”woof ");}} public static void main(String[] args) { class Dogcatimplements Dog, Cat{} test(new Dogcat()); } static void test(Object obj) { def x = (?)obj; x.meow (); x.bark (); } @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 51. How to cast to a type without declaring it? static void test(Object obj) { // A. Will that work? Dog& Catx = (Dog& Cat) obj; x.meow (); x.bark (); } static void test(Object obj) { // B. Will that work? ((Consumer<? extends Dog& Cat>)(x -> { x.meow (); x.bark (); })).accept((Dog& Cat)obj); } static void test(Object obj) { // C. Will that work? Optional.of((Dog& Cat) obj) .ifPresent(x -> { x.meow (); x.bark (); });} // D. You’re two sick bastards. interface Cat{ default void meow() {System.out.println(”meow");}} interface Dog{ default void bark() {System.out.println(”woof");}} public static void main(String[] args) { class Dogcat implements Dog, Cat{} test(new Dogcat()); } @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 52. @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 53. How to cast to a type without declaring it? static void test(Object obj) { // A. Will that work? Dog & Cat x = (Dog & Cat) obj; x.meow(); x.bark(); } static void test(Object obj) { // B. Will that work? ((Consumer<? extends Dog & Cat>)(x -> { x.meow(); x.bark(); })).accept((Dog & Cat)obj); } static void test(Object obj) { // C. Will that work? Optional.of((Dog & Cat) obj) .ifPresent(x -> { x.meow(); x.bark(); });} // D. You’re two sick bastards. interface Cat{ default void meow() {System.out.println(”meow");}} interface Dog{ default void bark() {System.out.println(”woof");}} public static void main(String[] args) { static class Dogcat implements Dog, Cat{} test(new Dogcat()); } @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 54. Bill Gates explains how that works @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 55. static void test(Object obj) { // C. Will that work? Optional.of((Dog & Cat) obj) .ifPresent(x -> { x.meow(); x.bark(); });} @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 56. @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 57. Viktor Gamov and Baruch Sadogursky call customer service: @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 58. What will be the output? 1. HOTEL ECHO LIMA LIMA OSCAR/ HOTEL ECHO LIMA LIMA OSCAR 2. HELLO / HOTEL ECHO LIMA LIMA OSCAR 3. HOTEL ECHO LIMA LIMA OSCAR/ HELLO 4. HELLO/HELLO public class Test { String str; void run() { str = "hello "; Supplier<String> s1 = str::toUpperCase; Supplier<String> s2 = () -> str.toUpperCase(); str = "Hotel Echo Lima Lima Oscar "; System.out.println(s1.get()); System.out.println(s2.get()); } }
  • 59. @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 60. What will be the output? 1. HOTEL ECHO LIMA LIMA OSCAR/ HOTEL ECHO LIMA LIMA OSCAR 2. HELLO / HOTEL ECHO LIMA LIMA OSCAR 3. HOTEL ECHO LIMA LIMA OSCAR/ HELLO 4. HELLO/HELLO public class Test { String str; void run() { str = ”hello"; Supplier<String> s1 = str::toUpperCase; Supplier<String> s2 = () -> str.toUpperCase(); str = ”Hotel Echo Lima Lima Oscar"; System.out.println(s1.get()); System.out.println(s2.get()); } }
  • 61. @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 62. What will happen? 1. ConcurrentModificationException 2. ArrayIndexOutOfBoundsException 3. NullPointerException 4. No exceptions,all good List<String> list = new ArrayList<>(Arrays.asList("Arnie", "Chuck", "Slay")); list.stream().forEach(x -> { if(x.equals("Chuck")) { list.remove(x); } }); @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 63. @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 64. Java 8 vs Chuck Norris @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 65. What will happen? A. ConcurrentModificationException B. ArrayIndexOutOfBoundsException C. NullPointerException D. No exceptions,all good List<String> list = new ArrayList<>(Arrays.asList("Arnie", "Chuck", "Slay")); list.stream().forEach(x -> { if(x.equals("Chuck")) { list.remove(x); } }); @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 66. Here’s why: stream().forEach() à spliterator().forEachRemaining() forEachRemaining checks for mod count once,in the end Removing element adds null to the end of the array: ["Arne", "Chuck", "Slay"] à ["Arne", "Slay", null] On the last iteration if(null.equals("Chuck")) fails with NPE (didn’t get to CME) Use list.removeIf("Chuck"::equals); @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 67. @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 68.
  • 69. System.out.println(Optional.of("rtfm").orElseGet(null)); System.out.println(Optional.empty().map(null).orElse("rtfm")); What will be the output? A. rtfm / rtfm B. rtfm / NullPointerException C. NullPointerException / NullPointerException D. NullPointerException / rtfm @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 70. @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 71. System.out.println(Optional.of("rtfm").orElseGet(null)); System.out.println(Optional.empty().map(null).orElse("rtfm")); What will be the output? A. rtfm /rtfm B. rtfm / NullPointerException C. NullPointerException / NullPointerException D. NullPointerException / rtfm @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 72. @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 73. @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 74. @jbaruch @gamussa #javapuzzlersng #codemash http://jfrog.com/shownotes
  • 76. - Write readable code! - Comment all the tricks - Sometimes it’s a bug - Static code analysis FTW - intellij IDEA! - Rtfm - Don’t abuse lambdas and streams!
  • 77. - Trust us, we have much more where those came from. - Puzzlers? Gotchas? Fetal position inducing behavior? - puzzlers jfrog.com
  • 78. Did you like it? Praise us on twitter and in the feedback form! - javapuzzlersng - gamussa - Jbaruch -http://jfrog.com/shownotes Didn’t like it? /dev/null