My BlueJ IDE is showing this error when I try to compile the class. I can't see what I'm doing wrong.
相关问题
- 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
This is a private method and local variables don't get default values, they have to be initialized. Consider a case where control doesn't go inside if block, then your variable contains no value, hence the error.
If the condition in the if clause is not true, the variable is not assigned. In this case, the return that follows references an uninitialized variable.
Local variables should be initialized with value before using it .Something like this :
The compiler complains because local variables are not assigned any value by default. So at run time if the
if()
condition fails then the variable will not be assigned any value and in that case what value should the run time return back to the caller of the function ? Hence initialize it with some default value.Before you can use a variable inside your if block , you need to initialize it.
Try this :
Instead of :
Keep in mind though that your variable will remain 0 if your condition returns false as you haven't specified an else block.