I am listening user location and trying to do a distance calculation based on a longitude latitude value that i am pulling from database.The problem is i cannot access location.getLatitude() because compiler says me that i need to declare location final.But since its changing i cant do that.
That appears to be Android code, so I shall move you to our Android forum.
Yes, local variables used in a local class, or in Java8+, in a λ must be “effectively final”. In Java7 and apparently in Android too, that means you need to use the final keyword. In Java8+ you can get away with never reassigning the local variable; in fact the compiler error you are seeing wouldn't have occurred in Java8.
Please don't use screenshots to post your code.
posted 9 months ago
I cant write Location final location
Why not? Please explain what the problem is.
Did you try if? What happened?
Note: the final keyword goes before the type name: final Location