Prevent usage of default constructor

后端 未结 5 497
-上瘾入骨i
-上瘾入骨i 2020-12-13 23:30

Is there a way to prevent the usage of the default constructor?

All I can think of is throwing an exception, but I would like something that causes a compile time er

5条回答
  •  难免孤独
    2020-12-13 23:46

    Make it private.

    So,

    class SomeClass
    {
        private SomeClass()
        {
        }
    
        public SomeClass(int SomeParam)
        {
        }
    }
    

提交回复
热议问题