Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Annotation from Boyarsky's OCP11 book

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi, annotation elements can be class(which we created own class). I saw this sentence on Boyarsk's book:
"Similar to a default element value, an annotation element cannot be declared with just any type. It must be
a primitive type, a String, a Class, an enum, another annotation, or an array of any of these types"
 
Bartender
Posts: 1737
63
Eclipse IDE Postgres Database C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That confused me the first time that I read it, too.

No, it can't just be any class.

In Java, there is an actual class called Class, like a dog named "Dog":

https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Class.html

It is only this type, and not any other Class or class in the world, that is an acceptable, legal type.

This class named Class gets used very heavily in a relatively advanced Java technique called Reflection.

Reflection is 95%+ off-topic for even the 819, it is important in the industry for advanced Java programming but you don't need to know about it for the exams.

So just know that java.lang.Class is the only class they mean in this section on annotations.

For general Java use, please know it would be a terrible idea to ever try to create your OWN class named Class, because Java's is right there in the java.lang package which would make life VERY confusing for everyone if you did so.
 
A magnificient life is loaded with tough challenges. En garde tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic