0

I've been reviewing some code and I found the following for a field:

private List<String> listOfStrings = java.util.ArrayList<String>();

When would it be preferable to use this code as opposed to:

import java.util.ArrayList;

...

private List<String> listOfStrings = new ArrayList<String>();

Is there any benefit, apart from the difference in syntax?

0

1 Answer 1

5

The only other possible benefit would be in a situation where another class called ArrayList exists. For instance:

package foo.bar;

class ArrayList { /* ... */ }

Then, if you wanted to use both this and the java.util class in the same file, you'd need to use the fully qualified name of one or both classes.

Sign up to request clarification or add additional context in comments.

1 Comment

True. Although anyone willingly creating a class called ArrayList in anything but a sandbox should suffer a horrible punishment.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.