|
|
Line 1: |
Line 1: |
− | CURRENTLY THIS IS JUST A PLACEHOLDER DUPLICATING THE CONTENT OF JAVA9/EXAMPLES - ETA : 1ST APRIL 2018
| + | ALPHA QUALITY NOW - EXPECTED TO BE COMPLETE BY : 1ST APRIL 2018 |
| | | |
| This is an informal page listing examples of features that are implemented by the [https://marketplace.eclipse.org/content/java-10-support-oxygen Java 10 Support for Oxygen]. You are welcome to try out these examples. If you find bugs, please file a bug after checking for a duplicate entry [https://bugs.eclipse.org/bugs/buglist.cgi?cmdtype=dorem&list_id=17341573&namedcmd=J10.Open&remaction=run&sharer_id=152344 here]. | | This is an informal page listing examples of features that are implemented by the [https://marketplace.eclipse.org/content/java-10-support-oxygen Java 10 Support for Oxygen]. You are welcome to try out these examples. If you find bugs, please file a bug after checking for a duplicate entry [https://bugs.eclipse.org/bugs/buglist.cgi?cmdtype=dorem&list_id=17341573&namedcmd=J10.Open&remaction=run&sharer_id=152344 here]. |
Line 80: |
Line 80: |
| ! colspan="3" | Editing with Ease: Completion for 'var' | | ! colspan="3" | Editing with Ease: Completion for 'var' |
| |- | | |- |
− | ! scope="row" | Keyword Completion (1) | + | ! scope="row" | Basic context based var completion |
− | | In the module-info.java file of say second project, after <code> module first {</code>, press completion key (for eg, ctrl+space in windows) | + | | |
| <br> | | <br> |
| <br> | | <br> |
− | [[File:Keycomplete1.jpg]] | + | [[File:var.complete.jpg]] |
− | | keywords <code>exports</code>, <code>opens</code>, <code>requires</code>, <code>provides</code> and <code>uses</code> shown | + | | completes var since the place is appropriate |
− | |-
| + | |
− | ! scope="row" | Keyword Completion (2)
| + | |
− | | after <code>exports packagename</code>, or <code>opens packagename</code> press completion key
| + | |
− | | keyword to is shown as an option
| + | |
− | |-
| + | |
− | ! scope="row" | Package Completion
| + | |
− | | after <code>exports</code>, <code>opens</code>, <code>provides</code> or <code>uses</code>, press completion key
| + | |
− | | package completion shown.
| + | |
− | |-
| + | |
− | ! scope="row" | Type Reference Completion
| + | |
− | | after <code>exports</code>, <code>opens</code>, <code>provides</code> or <code>uses</code>, or optionally after a dot after a package, ie <code>exports packagename.</code> press completion key
| + | |
− | | Type completion shown.
| + | |
− | |-
| + | |
− | ! scope="row" | Implementation TypeRef Completion
| + | |
− | | after <code>provides typename with</code> press completion key
| + | |
− | | Type completion shown and these typereferences are implementations of the type given before with.
| + | |
| |- | | |- |
| ! colspan="3" | The Essential Utilities: Code Select, Hover, Navigate, Search and Rename | | ! colspan="3" | The Essential Utilities: Code Select, Hover, Navigate, Search and Rename |
This is an informal page listing examples of features that are implemented by the Java 10 Support for Oxygen. You are welcome to try out these examples. If you find bugs, please file a bug after checking for a duplicate entry here.
|
Feature / Steps
|
Expected Result
|
The Pre-requisite: Java 10 JRE Support
|
Add Java 10 JRE
|
Use Eclipse Preferences -> Java -> Installed JREs -> Add
|
Java 10 JRE recognized as a valid JRE
|
Project JRE
|
In Package Explorer Use Project Context Menu and add Java 10 JRE |
JRE specific (eg Object) gets resolved in the project.
|
Package Explorer
|
Go to Package Explorer and expand the Java 10 JRE |
Modules (eg java.base etc) are listed in the package explorer view
|
The First Step: Java 10 Compliance
|
Set Project Compliance in Package Explorer
|
Context Menu of Project -> Properties -> Set project-specific, drop down to 10
|
No compiler errors
|
Basic Necessity : Compilation and Error Reporting
|
Positive Compilation
|
Use the following code:
package packvar;
import java.util.ArrayList;
import java.util.List;
public class VarUsage {
public static void main(String[] args) {
String s = new String("Hello World");
var x = s; // var allowed in the variable declaration
System.out.println(x);
List<String> l = new ArrayList<>();
l.add("List.Hello");
for (var lx : l) { // var allowed in enhanced for loop
System.out.println(lx);
}
}
}
|
code compiles
|
Compiler Error Cases
|
package packvar;
public class VarError {
public static void main(String[] args) {
String s = new String("Hello");
var x; // compiler error: Cannot use 'var' on variable without initializer
var y = null; // compiler error: Cannot infer type for local variable initialized to 'null'
}
}
|
compiler errors are shown
|
Editing with Ease: Completion for 'var'
|
Basic context based var completion
|
|
completes var since the place is appropriate
|
The Essential Utilities: Code Select, Hover, Navigate, Search and Rename
|
Module Select & Hover
|
In the module-info.java file of the first project, select second in the requires second; directive
|
Hover appears
|
Module Select, Hover & Navigate
|
In the above scenario, after hover appears, click on the navigate
|
module-info.java file of second opened
|
Module Select, & Search
|
In the module-info.java file of the second project, select second in module declaration module second { and search for references
|
In the search view, the reference in directive requires second; in file first -> module-info.java is shown.
|
Package Search
|
create package pack1 to the project first.
add exports pack1; directive in module-info.java file of first.
search for references of pack1
|
In the search view, the reference of pack1 in directive exports pack1; in file first -> module-info.java is shown, similar to other pack1 references if any
|
Type Search
|
create Type X in the project first, add directive uses X; in module-info.java file of first, and search for references of X
|
In the search view, the reference of X in directive uses X; in file first -> module-info.java is shown, similar to other X references if any
|
Code Select & Rename
|
in module-info.java file of first, select X in directive uses X; and rename to X11
|
rename exhibits usual behavior - renames definition and references of X to X11
|
The Outlier: Milling Project Coin Enhancements
|
@Safevarargs
|
@SafeVarargs is now allowed on private instance methods. There is even a support of quick assist for that. Use the following code which has warnings, and use the quick assist at the point mentioned in the comment
package packsafe;
import java.util.ArrayList;
import java.util.List;
public class SafeVar {
private int getLen(List<String>...list) {
List<String>[] l = list;
return l.length;
}
public static void main(String[] args) {
SafeVar x = new SafeVar();
List<String> l = new ArrayList<>();
int len = x.getLen(l); // Use Quick Assist of SafeVarargs here<br>
System.out.println("Length:" + len);
}
}
|
@SafeVarargs inserted before getLen() and the warnings go away
|
Effectively Final AutoCloseables
|
Effectively-final variables are allowed to be used as resources in the try-with-resources statement. The code below has an error. Try removing the line t1 = null; // Remove this code .
package packtry;
import java.io.Closeable;
import java.io.IOException;
class Two implements Closeable {
@Override
public void close() throws IOException {
// nothing
}
}
public class TryStmtTwo {
public void foo() throws IOException {
Two t1 = new Two();
try (t1; final Two t2 = new Two()) {
// Empty by design
}
t1 = null; // Remove this code
}
public static void main(String[] args) {
System.out.println("Done");
}
}
|
Code without errors. For the more inquisitive, check the generated code to see that the close is generated for t1 as well which is not a final variable but an effectively final variable.
|
Anonymous Diamond
|
In the following code, there is a warning about Y being a raw type and need to be parameterized. with Java 9 support, just add a diamond operator after Y.
public class Dia {
@SuppressWarnings("unused")
public static void main(String[] args) {
Y<?> y1 = new Y(){}; // Change this to new Y<>(){}
}
}
class Y<T> {}
|
Diamond operator <> accepted and code compiles without warning
|
Illegal Underscore
|
Underscore is an illegal identifier from Java 9 onwards. Uncomment the commented line in the following example
public class UnderScore {
//Integer _ ;
}
|
error: "'_' should not be used as an identifier, since it is a reserved keyword from source level 1.8 on"
|
Private Methods
|
private interface methods are allowed. Change the default of worker to private
public interface I {
default void worker() {}<
default void foo() {
worker();
}
default void bar() {
worker();
}
}
|
Code compiles with private as well. Note that this is a useful feature if two default methods wants to share the worker code and does not want the worker to be an public interface method.
|
Coming Soon to an Eclipse Version nearby you: The Java 9 DOM AST for module, Automatic Modules support, Quick Fixes and more...Watch this space for updates.
|