{"id":3947,"date":"2017-08-10T13:46:34","date_gmt":"2017-08-10T11:46:34","guid":{"rendered":"http:\/\/www.tutego.de\/blog\/javainsel\/?p=3947"},"modified":"2017-08-10T13:46:34","modified_gmt":"2017-08-10T11:46:34","slug":"was-eclipse-bisher-bei-java-9-untersttzt","status":"publish","type":"post","link":"https:\/\/www.tutego.de\/blog\/javainsel\/2017\/08\/was-eclipse-bisher-bei-java-9-untersttzt\/","title":{"rendered":"Was Eclipse bisher bei Java 9 unterst&uuml;tzt"},"content":{"rendered":"<p>Siehe <a href=\"https:\/\/wiki.eclipse.org\/Java9\/Examples\">https:\/\/wiki.eclipse.org\/Java9\/Examples<\/a><\/p>\n<p><b>Feature<\/b> \/ Steps     <br \/>Expected Result<\/p>\n<p>The Pre-requisite: Java 9 JRE Support<\/p>\n<p>Add Java 9 JRE    <br \/>Use Eclipse Preferences -&gt; Java -&gt; Installed JREs -&gt; Add<\/p>\n<p><a href=\"https:\/\/wiki.eclipse.org\/File:Addj9.jpg\"><img loading=\"lazy\" decoding=\"async\" alt=\"Addj9.jpg\" src=\"https:\/\/wiki.eclipse.org\/images\/8\/81\/Addj9.jpg\" width=\"702\" height=\"684\" \/><\/a><\/p>\n<p>Java 9 JRE recognized as a valid JRE<\/p>\n<p>Project JRE    <br \/>In Package Explorer Use Project Context Menu and add Java 9 JRE     <br \/>JRE specific (eg Object) gets resolved in the project.<\/p>\n<p>Package Explorer    <br \/>Go to Package Explorer and expand the Java 9 JRE     <br \/>Modules (eg java.base etc) are listed in the package explorer view<\/p>\n<p>The First Step: Module Creation<\/p>\n<p>Manual    <br \/>Context Menu of src -&gt; New -&gt; File &#8211; give the module-info.java as name     <br \/>no compiler errors<\/p>\n<p>Automatic    <br \/>Context Menu of Project -&gt; Cofigure -&gt; Create module-info. <\/p>\n<p><a href=\"https:\/\/wiki.eclipse.org\/File:AutomoduleCreate.jpg\"><img loading=\"lazy\" decoding=\"async\" alt=\"AutomoduleCreate.jpg\" src=\"https:\/\/wiki.eclipse.org\/images\/0\/01\/AutomoduleCreate.jpg\" width=\"578\" height=\"738\" \/><\/a><\/p>\n<p>A default module-info.java with all packages exported should be created<\/p>\n<p>Basic Necessity : Compilation, Module Dependency &amp; Error Reporting<\/p>\n<p>Unspecified Dependency    <br \/>create projects &quot;first&quot; and &quot;second&quot; and create module-info.java files in each of giving the module names &quot;first&quot; and &quot;second&quot; respectively.<\/p>\n<p>In the first module add the directive <code>requires second; <\/code>. This initial configuration would look something similar to the one shown in the figure.     <br \/><a href=\"https:\/\/wiki.eclipse.org\/File:Initmods.jpg\"><img loading=\"lazy\" decoding=\"async\" alt=\"Initmods.jpg\" src=\"https:\/\/wiki.eclipse.org\/images\/9\/99\/Initmods.jpg\" width=\"736\" height=\"514\" \/><\/a><\/p>\n<p>Compiler gives error &quot;second cannot be resolved to a module&quot;<\/p>\n<p>Define Dependency    <br \/>In the above scenario, add Project second as a dependent project for project first     <br \/>Compiler error goes away<\/p>\n<p>Duplicate Dependency    <br \/>Continuing from the above scenario, add a duplicate <code>requires second;<\/code> directive in the module-info.java file of the first     <br \/>Compiler gives error &quot;Duplicate requires entry: second&quot;<\/p>\n<p>Circular Dependency    <br \/>add a circular dependency ie <\/p>\n<p>add second project dependent on first    <br \/>add <code>requires first;<\/code> directive in the module-info.java file of the second project ie replace <code>\/\/ empty by design<\/code> comment by this directive<\/p>\n<p>Two compiler errors &quot; Cycle exists in module dependencies, Module second requires itself via first&quot;<\/p>\n<p>Editing with Ease: Completion in module-info.java file<\/p>\n<p>Keyword Completion (1)    <br \/>In the module-info.java file of say second project, after <code>module first {<\/code>, press completion key (for eg, ctrl+space in windows) <\/p>\n<p><a href=\"https:\/\/wiki.eclipse.org\/File:Keycomplete1.jpg\"><img loading=\"lazy\" decoding=\"async\" alt=\"Keycomplete1.jpg\" src=\"https:\/\/wiki.eclipse.org\/images\/f\/f2\/Keycomplete1.jpg\" width=\"470\" height=\"370\" \/><\/a><\/p>\n<p>keywords <code>exports<\/code>, <code>opens<\/code>, <code>requires<\/code>, <code>provides<\/code> and <code>uses<\/code> shown<\/p>\n<p>Keyword Completion (2)    <br \/>after <code>exports packagename<\/code>, or <code>opens packagename<\/code> press completion key     <br \/>keyword to is shown as an option<\/p>\n<p>Package Completion    <br \/>after <code>exports<\/code>, <code>opens<\/code>, <code>provides<\/code> or <code>uses<\/code>, press completion key     <br \/>package completion shown.<\/p>\n<p>Type Reference Completion    <br \/>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     <br \/>Type completion shown.<\/p>\n<p>Implementation TypeRef Completion    <br \/>after <code>provides typename with<\/code> press completion key     <br \/>Type completion shown and these typereferences are implementations of the type given before with.<\/p>\n<p>The Essential Utilities: Code Select, Hover, Navigate, Search and Rename<\/p>\n<p>Module Select &amp; Hover<\/p>\n<p>In the module-info.java file of the first project, select <code>second<\/code> in the <code>requires second;<\/code> directive     <br \/><a href=\"https:\/\/wiki.eclipse.org\/File:Hover.jpg\"><img loading=\"lazy\" decoding=\"async\" alt=\"Hover.jpg\" src=\"https:\/\/wiki.eclipse.org\/images\/5\/5c\/Hover.jpg\" width=\"864\" height=\"584\" \/><\/a><\/p>\n<p>Hover appears<\/p>\n<p>Module Select, Hover &amp; Navigate    <br \/>In the above scenario, after hover appears, click on the navigate     <br \/>module-info.java file of second opened<\/p>\n<p>Module Select, &amp; Search<\/p>\n<p>In the module-info.java file of the second project, select second in module declaration <code>module second {<\/code> and search for references     <br \/><a href=\"https:\/\/wiki.eclipse.org\/File:Modsearch2.jpg\"><img loading=\"lazy\" decoding=\"async\" alt=\"Modsearch2.jpg\" src=\"https:\/\/wiki.eclipse.org\/images\/7\/7f\/Modsearch2.jpg\" width=\"724\" height=\"544\" \/><\/a><\/p>\n<p>In the search view, the reference in directive <code>requires second;<\/code> in file first -&gt; module-info.java is shown.<\/p>\n<p>Package Search<\/p>\n<p>create package <code>pack1<\/code> to the project first.     <br \/>add <code>exports pack1;<\/code> directive in module-info.java file of first.     <br \/>search for references of <code>pack1<\/code><\/p>\n<p>In the search view, the reference of <code>pack1<\/code> in directive <code>exports pack1;<\/code> in file first -&gt; module-info.java is shown, similar to other <code>pack1<\/code>references if any<\/p>\n<p>Type Search    <br \/>create Type <code>X<\/code> in the project first, add directive <code>uses X;<\/code> in module-info.java file of first, and search for references of X     <br \/>In the search view, the reference of <code>X<\/code>in directive<code>uses X;<\/code> in file first -&gt; module-info.java is shown, similar to other <code>X<\/code>references if any<\/p>\n<p>Code Select &amp; Rename    <br \/>in module-info.java file of first, select <code>X<\/code> in directive <code>uses X;<\/code> and rename to <code>X11<\/code>     <br \/>rename exhibits usual behavior &#8211; renames definition and references of <code>X<\/code>to <code>X11<\/code><\/p>\n<p>The Outlier: Milling Project Coin Enhancements<\/p>\n<p>@Safevarargs    <br \/><code>@SafeVarargs<\/code> 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 <\/p>\n<pre>package packsafe;\nimport java.util.ArrayList;\nimport java.util.List;&#160;&#160; public class SafeVar {\n\tprivate int getLen(List&lt;String&gt;...list) {\n\t\tList&lt;String&gt;[] l = list;\n\t\treturn l.length;\n\t}&#160;&#160; public static void main(String[] args) {\n\t\tSafeVar x = new SafeVar();\n\t\tList&lt;String&gt; l = new ArrayList&lt;&gt;();\n\t\tint len = x.getLen(l); \/\/ Use Quick Assist of SafeVarargs here&lt;br&gt;\n\t\tSystem.out.println(&quot;Length:&quot; + len);\n\t}\n}<\/pre>\n<p><code>@SafeVarargs<\/code>inserted before <code>getLen()<\/code> and the warnings go away<\/p>\n<p>Effectively Final Autoloseables<br \/>\n  <br \/>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 <code>t1 = null; \/\/ Remove this code <\/code>. <\/p>\n<pre>package packtry;\nimport java.io.Closeable;\nimport java.io.IOException;&#160;&#160; class Two implements Closeable {\n\t@Override\n\tpublic void close() throws IOException {\n\t\t\/\/ nothing\n\t}\n}\npublic class TryStmtTwo {&#160;&#160; public void foo() throws IOException {\n\t\tTwo t1 = new Two();\n\t\ttry (t1; final Two t2 = new Two()) {\n\t\t\/\/ Empty by design\n\t}\n\tt1 = null; \/\/ Remove this code\n\t}\n\tpublic static void main(String[] args) {\n\t\tSystem.out.println(&quot;Done&quot;);\n\t}\n}<\/pre>\n<p>Code without errors. For the more inquisitive, check the generated code to see that the close is generated for <code>t1<\/code> as well which is not a final variable but an effectively final variable.<\/p>\n<p>Anonymous Diamond<br \/>\n  <br \/>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. <\/p>\n<pre>public class Dia {\n@SuppressWarnings(&quot;unused&quot;)\n\tpublic static void main(String[] args) {\n\t\tY&lt;?&gt; y1 = new Y(){}; \/\/ Change this to new Y&lt;&gt;(){}\n\t}\n}\nclass Y&lt;T&gt; {}<\/pre>\n<p>Diamond operator <code>&lt;&gt;<\/code>accepted and code compiles without warning<\/p>\n<p>Illegal Underscore<br \/>\n  <br \/>Underscore is an illegal identifier from Java 9 onwards. Uncomment the commented line in the following example <\/p>\n<pre>public class UnderScore {\n\t\/\/Integer _ ;\n}<\/pre>\n<p>error: &quot;&#8217;_&#8216; should not be used as an identifier, since it is a reserved keyword from source level 1.8 on&quot;<\/p>\n<p>Private Methods<br \/>\n  <br \/>private interface methods are allowed. Change the <code>default<\/code> of worker to private <\/p>\n<pre>public interface I {\n\tdefault void worker() {}&lt;&#160;&#160; default void foo() {\n\t\tworker();\n\t}&#160;&#160; default void bar() {\n\t\tworker();\n\t}\n}<\/pre>\n<p>Code compiles with <code>private<\/code>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.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Siehe https:\/\/wiki.eclipse.org\/Java9\/Examples Feature \/ Steps Expected Result The Pre-requisite: Java 9 JRE Support Add Java 9 JRE Use Eclipse Preferences -&gt; Java -&gt; Installed JREs -&gt; Add Java 9 JRE recognized as a valid JRE Project JRE In Package Explorer Use Project Context Menu and add Java 9 JRE JRE specific (eg Object) gets resolved [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","_links_to":"","_links_to_target":""},"categories":[7,85],"tags":[8],"class_list":["post-3947","post","type-post","status-publish","format-standard","hentry","category-entwicklungsumgebung","category-java-9","tag-eclipse"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/posts\/3947","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/comments?post=3947"}],"version-history":[{"count":1,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/posts\/3947\/revisions"}],"predecessor-version":[{"id":3948,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/posts\/3947\/revisions\/3948"}],"wp:attachment":[{"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/media?parent=3947"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/categories?post=3947"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/tags?post=3947"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}