Raw functions how to use them

260 views Asked by At

Hi, I have this application with an @Raw annotation. My question is, if these two functions in the code below are valid because of the RAW annotation and WHY ? this.setX(some.getX()); or some.setX(this.getX());

 /** 
 * @invar … 
 * | getX() <= 0 
 */ 
public class SomeClass { 
 @Raw 
 public float getX() { 
 return this.x; 
 } 
 public void setX(float x) throws IllegalArgumentException { 
 if (x > 0) 
 throw new IllegalArgumentException(); 
 this.x = x; 
 } 
 private float x; 
 @Raw 
 public void someMethod(SomeClass some) throws NullPointerException { 
 this.setX(some.getX()); 
 some.setX(this.getX()); 
 }
}
1

There are 1 answers

0
Zavior On BEST ANSWER

You dont specify where the @Raw annotation comes from, so I'll assume you mean the checker framework. From the docs:

This type qualifier belongs to the rawness type-system for tracking initialization. This type-system is not used on its own, but in conjunction with some other type-system that wants to ensure safe initialization. For instance, NullnessRawnessChecker uses rawness to track initialization of NonNull fields.

The functions in your code are valid and will work by themselves, too. Someone just wanted some safeguards to make sure the objects they are using are fully initialized.