interface - Why are default methods not allowed in annotation types in Java 8? -


Today I saw a glimpse of the wonderful world of annotations, so I applied my code, but I do not want to compile it: / p>

  public @interface some annotations {say public string 1 (default) "Hello World"; The default public string is called Halo 2 () {Return "Hello World"; }}   

What do you see in sayHello1 , how to specify the default logic for annotations.
What do I think, so, is not allowed to say hello 2 , which is available after Java 8.

Is providing similar functionality to me, or am I missing something here?

By default, java 5 can have access to the default method bodies (albeit very simple ones), while the interface had to wait until Java 8?

this

  say public string "halo 1" (default) "hello world";   

The default value of annotation element is providing this, if you have not given it in annotation, then it will be of that value, which will be.

There can be law announcements in the body of an annotation type, each of which has defined an element of annotation type. There is no element other than words defined in an annotation type, it clearly declares the methods.

and

An element of an annotation type can have a default value, which is specified by following the list of element (empty) parameters Is the keyword default and a ElementValue (§ 9.7.1).

then

  @ SomeNnotation // Say "Hello World" will be public square Foo {} in hello 1   

@SomeAnnotation (sayHello1 = "Other value") // "Other value" in Halo 1 will be the value of the public category Foo {}

Then

  some annotations n = ...; String value = NISAHL1 ();   

If you do not value the default , then you have to provide a price when you make a few comments.

This

  is called the default public string Hello 2 () {Return to "Hello World"; }   

There is a syntax for a default method in a interface since java. You can execute anything in this method. This is not true for an annotation which provides only metadata, not behavior

Also, why did the annotations have default method bodies (though very simple ones) Java 5, while the interface had to wait up to 8 Java?

They did not. The above two things are completely different.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -