Java ternary operator influence on generics type inference

Compiles for me fine in java 8. Earlier versions of Java might need more help return retval == null ? Collections.<String>emptyList() : retval; should work. EDIT This is due to improvements in Java 8 type inference as explained here http://openjdk.java.net/jeps/101 And here’s a blog with the highlights: http://blog.jooq.org/2013/11/25/a-lesser-known-java-8-feature-generalized-target-type-inference/

Enhanced for loop compiling fine for JDK 8 but not 7

This should actually compile fine for JDK 7 and 8. Quoting JLS section 14.14.2 (which is the same for the Java 7 specification): The enhanced for statement is equivalent to a basic for statement of the form: for (I #i = Expression.iterator(); #i.hasNext(); ) { {VariableModifier} TargetType Identifier = (TargetType) #i.next(); Statement } Rewriting the … Read more

Convert existing generics to diamond syntax

Oh yes, I have successfully done this on IntelliJ (free Community Edition). Menu > Analyze > Inspect Code… In the result, select “Java language level migration aids > Explicity type can be replaced with <>” Right click, run “Apply Fix ‘Replace with <>’” And you got diamonds. There was a bug about diamond on anomymous … Read more

Java 7 JVM VerifyError in Eclipse

Bug 353467 speaks about “using -XX:-UseSplitVerifier to activate the old verifier”. That is consistent with the JDK TM 6 Adoption Guide which describes that option as: Traditional verifier can be forced with the -XX:-UseSplitVerifier flag. Missing or incorrect StackMapTable attributes for version 50.0 class files can result in VerifyError exceptions. Tools that rewrite bytecode in … Read more

JavaFx Drag and Drop a file INTO a program

Here is a simple drag and drop example that just sets the file name and location. Drag files to it and it shows their name and location. Once you know that it should be a completely separate matter to actually play the file. It is primarily taken from Oracle’s documentation: https://docs.oracle.com/javafx/2/drag_drop/jfxpub-drag_drop.htm A minimal implementation needs … Read more

Java: print contents of text file to screen

Before Java 7: BufferedReader br = new BufferedReader(new FileReader(“foo.txt”)); String line; while ((line = br.readLine()) != null) { System.out.println(line); } add exception handling add closing the stream Since Java 7, there is no need to close the stream, because it implements autocloseable try (BufferedReader br = new BufferedReader(new FileReader(“foo.txt”))) { String line; while ((line = … Read more

Can there be a (Java 7) FileSystem for which a Path .isAbsolute() but has a null root?

Well, there are some obscure things with file systems. I made a few enterprise search crawlers, and somewhere down the road you will notice some strange file system things going on with paths. BTW: these are all implementations of custom (overridden) file systems, so no standard ones, and you can definitely argue for hours on … Read more

Properly installing java 8 along with java 7

The problem is that Java 8 installs a lot of stuff that you don’t really need: \windows\system32 contains Java 8 java.exe, javaw.exe and javaws.exe. Your path probably has system32 near the beginning, so these tend to be run by default. The system path variable starts with C:\programdata\Oracle\Java\javapath. This folder contains java.exe, javaw.exe and javaws.exe as … Read more

techhipbettruvabetnorabahisbahis forumu