Sometimes when you are debugging, you have unreachable code fragment. Is there anyway to suppress the warning?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
As Cletus tells us,
That said, at least for Eclipse, there is not a way to do this. With my Eclipse configuration, unreachable code causes a compile-time error, not just a warning. Also note this is different from "dead code," e.g.
for which Eclipse (by default) emits a warning, not an error.
Java has (primitive) support for debugging like this in that simple
if
on boolean constants will not generate such warnings (and, indeed when the evaluation is false the compiler will remove the entire conditioned block). So you can do:Likewise, if you are temporarily inserting an early termination for debugging, you might do it like so:
or
And note that the Java specification explicitly declares that constantly false conditional blocks are removed at compile time, and IIRC, constantly true ones have the condition removed. This includes such as:
According to the Java Language Specification:
You can sometimes turn unreachable code into dead code (e.g., the body of
if (false) {...}
). But it being an error is part of the language definition.The only way to do this on any compiler is
@SuppressWarnings("all")
.If you're using Eclipse, try
@SuppressWarnings("unused")
.