Local variables of same name in same scope, IDE display error but when I run the program, no run time error results

后端 未结 3 1041
误落风尘
误落风尘 2021-01-26 03:57

I understand that it is illegal to declare local variables of the same name in the same scope. I wrote this very simple class, and yes, the IDE does display an error next to

相关标签:
3条回答
  • 2021-01-26 04:38

    Because in run time. You never called your method "VariableWithSameName" and that's why. run time error will only occur if a system run onto an error . but compile time error will determine all possible errors that in can found during compilation

    0 讨论(0)
  • 2021-01-26 04:39

    Just adding my 2 cents, If you are wondering how a class with compile error is getting compiled , take a look here https://stackoverflow.com/a/7590454/6785908

    The IDE's internal compiler is - at least in some cases - able to keep going with the build, even when some classes don't compile fully. It will even produce class files for the broken classes if possible, generating methods which throw an exception as soon as they're called.

    0 讨论(0)
  • 2021-01-26 04:45

    This is a compile-time error. Presumably you successfully compiled before introducing the error and are still executing that .class file.

    0 讨论(0)
提交回复
热议问题