Is it possible to have a getter for a const?

前端 未结 4 1959
忘掉有多难
忘掉有多难 2020-12-19 06:16

Just curious, is there a way to have a getter for a constant variable? I have a sort of internal version number to ensure that two versions of a library are still speaking t

4条回答
  •  既然无缘
    2020-12-19 07:19

    Just do:

    public const Int16 protocol_version = 1;
    

    This will provide a public getter as a const cannot have a setter.

提交回复
热议问题