When does it make sense to use a public field?

后端 未结 8 1367
时光说笑
时光说笑 2021-02-18 16:52

This is a question I have had for a while now:

When does it make sense to expose a field publicly like so?

public class SomeClass()
{
   public int backi         


        
8条回答
  •  终归单人心
    2021-02-18 17:07

    When does it make sense to expose a field publicly?

    Among other places, on private classes as below.

    public class MyOuterClass
    {
          private class MyInnerClass
          {
                public int val ; // why bother w/boiler plate
          }
    }
    

提交回复
热议问题