This question already has an answer here:
- Java: What does ~ mean 5 answers
- What “~” (tilde) operator does in Java? [duplicate] 1 answer
In another stack overflow post, I saw some Java code like this, related to reflection:
public void setFinalStatic(Field field, Object newValue) throws Exception { field.setAccessible(true);
Field modifiersField = Field.class.getDeclaredField("modifiers"); modifiersField.setAccessible(true); modifiersField.setInt(field, field.getModifiers() & ~Modifier.FINAL); field.set(null, newValue); }
I noticed that there is a squiggly line "~" in front of Modifier.FINAL. What is this "~"? I've never seen it before in Java code. I copied and pasted the code into Eclipse and it compiles so it's valid code.
Thank you in advance.
Aucun commentaire:
Enregistrer un commentaire