问题
There seem to be two different JSRs for annotations.
JSR-305: Annotations for Software Defect Detection (additional resource)
JSR-308: Annotations on Java Types (additional resource)
Both seem to be oriented towards static code analysis.
Do you know:
- which of the both is going to be either in Java SE 7 or Java EE 6?
- how "stable" is each JSR?
- does the one supersedes (or obsoletes) the other?
回答1:
I can answer your last question. They are not the same thing. 305 is about new annotations where you can already put them, which can help provide programmatic visibility into a design by contract system. So that if a certain method is supposed to not return null, or if a certain method is supposed to never receive a null parameter, it is possible to tell the system analyzing the annotations to look out for this specific case at this piece of code.
308 is about being able to annotate more things, such as a generic parameter and a type cast. I imagine a primary use for that is to be able to suppress warning on a specific type cast, instead of having to declare a local variable for that purpose. The @SuppressWarnings annotation already exists (whereas JSR-305 would look to define new ones), but in JSR-308 it could be applied to more cases.
According to this 308 will be part of Java7, which would imply it is quite well along to being stable. JSR-305 isn't on the list, so it doesn't look like it will make it to Java7.
回答2:
According to this document, last updated on 2010-09-19, JSR 308 is "Deferred to JDK 8 or later": http://openjdk.java.net/projects/jdk7/features/
回答3:
For future readers, JSR 308 is being integrated into Java 7. Some of its changes have already been pushed to the public betas of Java 7. JSR305 however didn't make the cut.
来源:https://stackoverflow.com/questions/1476757/jsr305-vs-jsr308-java-type-anotations-which-is-going-to-be-the-standard