Immutable Type: public final fields vs. getter

前端 未结 8 898
臣服心动
臣服心动 2020-11-30 04:48

I need a small Container-Class for storing some Strings which should be immutable. As String itself is an immutable type, I thought of something like that:

p         


        
8条回答
  •  醉梦人生
    2020-11-30 05:15

    It is not very clear if someone is going to use your code through an API. You are also missing an opportunity to validate the input, if you are going to require some later.

提交回复
热议问题