{"id":1222,"date":"2012-02-01T14:59:00","date_gmt":"2012-02-01T12:59:00","guid":{"rendered":"http:\/\/www.tutego.de\/blog\/javainsel\/?p=1222"},"modified":"2012-02-01T14:59:00","modified_gmt":"2012-02-01T12:59:00","slug":"erster-draft-fr-annotations-on-java-types-jsr-308","status":"publish","type":"post","link":"https:\/\/www.tutego.de\/blog\/javainsel\/2012\/02\/erster-draft-fr-annotations-on-java-types-jsr-308\/","title":{"rendered":"Erster Draft f&uuml;r &ldquo;Annotations on Java Types&rdquo; (JSR-308)"},"content":{"rendered":"<p><a href=\"http:\/\/jcp.org\/aboutJava\/communityprocess\/edr\/jsr308\/index2.html\">http:\/\/jcp.org\/aboutJava\/communityprocess\/edr\/jsr308\/index2.html<\/a>. Aus der Spezi:<\/p>\n<blockquote>\n<p>JSR 308 extends Java to allow annotations on any use of a type, and on type parameter declarations.<\/p>\n<p>Beispiele:<\/p>\n<p>for generic type arguments to parameterized classes:     <br \/>Map&lt;@NonNull String, @NonEmpty List&lt;@Readonly Document&gt;&gt; files;      <br \/> for generic type arguments in a generic method or constructor invocation:      <br \/>o.&lt;@NonNull String&gt;m(&quot;&#8230;&quot;);      <br \/> for type parameter bounds, including wildcard bounds:      <br \/>class Folder&lt;F extends @Existing File&gt; { &#8230; }      <br \/>Collection&lt;? super @Existing File&gt;      <br \/> for class inheritance:      <br \/>class UnmodifiableList&lt;T&gt; implements @Readonly List&lt;@Readonly T&gt; { &#8230; }      <br \/> for throws clauses:      <br \/>void monitorTemperature() throws @Critical TemperatureException { &#8230; }      <br \/> for typecasts:      <br \/>myString = (@NonNull String) myObject;      <br \/>It is not permitted to omit the Java type, as in myString = (@NonNull) myObject;.      <br \/> for constructor invocation results (that is, for object creation):      <br \/>new @Interned MyObject()      <br \/>new @NonEmpty @Readonly List&lt;String&gt;(myNonEmptyStringSet)      <br \/>myVar . new @Tainted NestedClass      <br \/>For generic constructors (JLS \u00a78.8.4), the annotation follows the explicit type arguments (JLS \u00a715.9):      <br \/>new &lt;String&gt; @Interned MyObject()      <br \/> for type tests:      <br \/>boolean isNonNull = myString instanceof @NonNull String;      <br \/>It is not permitted to omit the Java type, as in myString instanceof @NonNull.<\/p>\n<\/blockquote>\n<p align=\"left\">Damit einher geht eine krasse \u00c4nderung, das bei Objektmethoden einfach so ein this \u00dcbergeben werden kann.<\/p>\n<blockquote>\n<p align=\"left\">It is permitted to explicitly declare the method receiver as the \ufb01rst formal parameter<\/p>\n<p>As an example, here are the standard de\ufb01nitions for toString and equals:     <br \/>class MyClass {      <br \/>&#8230;      <br \/>public String toString() { &#8230; }      <br \/>public boolean equals(Object other) { &#8230; }      <br \/>}      <br \/>It is equivalent to write instead      <br \/>class MyClass {      <br \/>&#8230;      <br \/>public String toString(MyClass this) { &#8230; }      <br \/>public boolean equals(MyClass this, Object other) { &#8230; }      <br \/>}      <br \/>and then it would be possible to annotate the receiver\u2019s type:      <br \/>class MyClass {      <br \/>&#8230;      <br \/>public String toString(@Readonly MyClass this) { &#8230; }      <br \/>public boolean equals(@Readonly MyClass this, @Readonly Object other) { &#8230; }      <br \/>}<\/p>\n<\/blockquote>\n<p align=\"left\">Interessant finde ich noch:<\/p>\n<blockquote>\n<p>To ease the transition from standard Java SE 7 code to code with type annotations, the reference implementation     <br \/>recognizes the type annotations when surrounded by comment markers:      <br \/>List&lt;\/*@Readonly*\/ Object&gt; myList;      <br \/>This permits use of both standard Java SE 7 tools and the new annotations even before Java SE 8 is released<\/p>\n<\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>http:\/\/jcp.org\/aboutJava\/communityprocess\/edr\/jsr308\/index2.html. Aus der Spezi: JSR 308 extends Java to allow annotations on any use of a type, and on type parameter declarations. Beispiele: for generic type arguments to parameterized classes: Map&lt;@NonNull String, @NonEmpty List&lt;@Readonly Document&gt;&gt; files; for generic type arguments in a generic method or constructor invocation: o.&lt;@NonNull String&gt;m(&quot;&#8230;&quot;); for type parameter bounds, including wildcard [&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":[66],"tags":[],"class_list":["post-1222","post","type-post","status-publish","format-standard","hentry","category-java-8"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/posts\/1222","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=1222"}],"version-history":[{"count":1,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/posts\/1222\/revisions"}],"predecessor-version":[{"id":1223,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/posts\/1222\/revisions\/1223"}],"wp:attachment":[{"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/media?parent=1222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/categories?post=1222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tutego.de\/blog\/javainsel\/wp-json\/wp\/v2\/tags?post=1222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}