I have read here that in Java it is possible for two variables having same name but different type to co-exist in the same scope. What I mean is this
class test
{
private int x;
private double x;
}
But all java IDE do not allow such code. I want to know whether such a code is really syntactically correct, or simply the IDE do not allow such code to prevent ambiguity.
Anyway here is the extract from the website
"If you’re lucky, you might be able to recompile the output from Jad. However, the Java VM has more lenient rules for variable naming than the Java language itself. For instances, a valid class file can have several variables named ‘a’, as long as they have different types. If you decompile such a class, the source code you get will not be valid.
JAD will usually rename the offending fields, and make a recompilable file… the only problem being that the recompiled file won’t be compatible with the original classes."
You cannot have variables having same name (but different type) to exist in the same scope.
Consider if it was possible then how would the java compiler determine which one you meant.
Consider this code snippet
The java compiler cannot understand which x you are actually referring to. So such a code is not syntactically correct and not compilable.
However there exists tools such as ClassEditor which can modify the generated class file after it is created. There it is possible to change the name two variables to same.
However such a class is not necessarily runnable by the java jvm.
The software which you have quoted i.e
JADcan rename such duplicate named variables in the class file so that the source code which you will be getting will actually be syntactically correct