Is final String s = “Hello World” same as String s = “Hello World”?

前端 未结 3 1786
青春惊慌失措
青春惊慌失措 2021-01-19 12:11

If a class is defined as final and we declare an instance of the final class... Would it make any difference? or is final in such cases would be re

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-19 12:24

    final on a variable has nothing to do with whether the class is final.

    final String s = "Hello World";
    s = "Goodbye";  // illegal
    
    String s2 = "Hello World";
    s2 = "Goodbye";  // legal
    

提交回复
热议问题