How to call a different constructor conditionally in Java?

后端 未结 5 1540
不思量自难忘°
不思量自难忘° 2020-12-11 16:16

Let\'s say someone gives you a class, Super, with the following constructors:

public class Super
{
    public Super();
    public Super(int arg)         


        
5条回答
  •  忘掉有多难
    2020-12-11 16:36

    Yeah, what @Johan Sjöberg said.

    Also looks like your example is highly contrived. There's no magical answer which would clear this mess :)

    Usually, if you have such a bunch of constructors it would be a good idea to refactor them as four separate classes (a class should be only responsible for one type of thing).

提交回复
热议问题