Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Java10/Examples"
Line 78: | Line 78: | ||
| compiler errors are shown | | compiler errors are shown | ||
|- | |- | ||
− | ! colspan="3" | | + | ! colspan="3" | Essential Utilities: Code Completion, Hover and Quick Fix. |
|- | |- | ||
! scope="row" | Basic context based var completion | ! scope="row" | Basic context based var completion | ||
Line 98: | Line 98: | ||
| completes var since the place is appropriate | | completes var since the place is appropriate | ||
|- | |- | ||
− | ! scope="row" | | + | ! scope="row" | Negative Case - no completion |
| | | | ||
− | |||
<br> | <br> | ||
<source lang="java"> | <source lang="java"> | ||
Line 109: | Line 108: | ||
} | } | ||
</source> | </source> | ||
+ | <br> | ||
[[File:var.nocomplete.jpg]] | [[File:var.nocomplete.jpg]] | ||
| does not offer 'var' as completion | | does not offer 'var' as completion | ||
− | + | ! scope="row" | Hover | |
− | + | | | |
− | + | ||
− | ! scope="row" | | + | |
− | | | + | |
− | + | ||
<br> | <br> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<source lang="java"> | <source lang="java"> | ||
− | package | + | package packvar; |
− | + | public class VarComplete { | |
− | + | public static void main(String[] args) { | |
− | + | String s = new String("hello"); | |
− | public class | + | var x = s; |
− | + | System.out.println(x); | |
− | + | } | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
} | } | ||
</source> | </source> | ||
− | + | <br> | |
− | + | [[File:var.hover.jpg]] | |
− | + | | shows javadoc of the type associated with var | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | | | + | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
|- | |- | ||
− | ! colspan="3" | | + | ! colspan="3" | More to come in Java 11 ! |
|} | |} |
Revision as of 12:55, 26 March 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 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 | |||
Essential Utilities: Code Completion, Hover and Quick Fix. | |||||
Basic context based var completion |
package packvar; public class VarComplete { public static void main(String[] args) { String s = new String("hello"); va // try completing here } } |
completes var since the place is appropriate | |||
Negative Case - no completion |
package packvar; public class VarComplete { va // complete here - 'var' not offered as a completion candidate } |
does not offer 'var' as completion | Hover |
package packvar; public class VarComplete { public static void main(String[] args) { String s = new String("hello"); var x = s; System.out.println(x); } } |
shows javadoc of the type associated with var |
More to come in Java 11 ! |