Question

When creating constructors with multiple arguments, is ok to use the generic String[] args or is it better to list the arguments? Does it really make any significant difference as the coding becomes more complicated?

public static void Something (String[] args) 
{
}

or

public static void Something (String lots, ... int some, ... etc) 
{
}
Was it helpful?

Solution

A String[] is suitable if your class has a single String[] that you need to construct it with.

It is not suitable if you need different types - how would you represent an int in a String[]? You would need some sort of convention and this would be prone to error and be overly complex to boot.

Use the right types for the class. It is normally OK to have several parameters for the class, but if there are 7 or more (rule of thumb - don't take this as gospel) it is probably doing too much (see Single Responsibility Principle).

Licensed under: CC-BY-SA with attribution
scroll top