@NotNull and @Nullable, contradicting java annotations -


it happened me accidentally did this:

@javax.annotation.nullable @javax.validation.constraints.notnull 

the compiler didn't complain , seemed work well.

now wondering internally happening when 2 or more annotations contradict each other. furthermore, order matter?

is this

@nullable @notnull 

the same this?

@notnull @nullable 

how working annotations in general? wins?

edit: looking general answer, not these 2 annotations

annotations don't bring logic code. each annotation should processed proper annotation processor. annotation processor guy makes annotation meaningful.

check official tutorial:

annotations, form of metadata, provide data program not part of program itself. annotations have no direct effect on operation of code annotate.

annotations have number of uses, among them:

  • information compiler — annotations can used compiler detect errors or suppress warnings.
  • compile-time , deployment-time processing — software tools can process annotation information generate code, xml files, , forth.
  • runtime processing — annotations available examined @ runtime.

let's consider these 2 particular annotations mentioned above. first of all, not mutual exclusive , have different nature.

the @javax.annotation.nullable part of jsr-305 , has opposite 1 - @javax.annotation.nonnull. these annotations designed annotate class fields, method params , method results. can use them code analyzers, 1 of them findbugs

the @javax.validation.constraints.notnull part of jsr-303 aka bean validation. annotation has nothing common @javax.annotation.nullable, since these annotations have different processors.

each time have doubts on annotation semantics, should check documentation, , of course can run code , see happen.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -