2. About me
Marek Parfianowicz
• Gdańsk University of Technology, ETI, distributed software systems
• Senior Software Engineer at Lufthansa Systems (2004-2012)
• Support Engineer and Software Developer at Spartez (since 2012)
o main developer of the Atlassian Clover
• C/C++, Java, Groovy, Scala
15. Method references - constructors
• generic constructors
ArrayList::new // raw list
ArrayList::<String>new // forbidden
ArrayList<String>::new // generic list
ArrayList<String>::<String>new // superfluous, but OK
JDK8
17. Generics with autoboxing (1)
• A compiler bug? A feature?
• A branch condition with autoboxed Boolean declared as a generic type
interface Data {
public <T> T getValue();
}
public boolean testGetValue(Data source) {
// shall we expect “Object” for source.getValue()?
}
18. Generics with autoboxing (2)
// fails under JDK6, compiles under JDK7+
public boolean testGetValue(Data source) {
if (source.getValue()) // Implicit conversion to Boolean via autoboxing
...
}
// … but compilation of this code fails under JDK7 with a message:
// Error: Operator && cannot be applied to java.lang.Object, boolean
public boolean testGetValue(Data source) {
if (source.getValue() && true)
…
}
20. Cast + generics
• Compiler bug; occurs in JDK6+JDK7; javac is unable to parse () with <>
public class Util {
@SuppressWarnings("unchecked")
public static <T> T cast(Object x) {
return (T) x;
}
static {
Util.<Object>cast(null); // OK
(Util.<Object>cast(null)).getClass(); // Error: illegal start of expression
}
}
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6481655