icrazybest
icrazybest

Reputation: 3

What is the advantages and disadvantages of writing return type java.util.Date or Date?

The methods is a basic part of the system core.

 public java.util.Date getCurDate(){...}
 public Date getCurDate(){...}

What is the advantages and disadvantages of writing this return type?

Upvotes: 0

Views: 392

Answers (2)

4nti
4nti

Reputation: 196

If there is no reason to assume there will be conflict with another class called "Date" then there is no need or advantage to write the full name.

Upvotes: 0

Always Learning
Always Learning

Reputation: 5581

The return type needs to specify an unambiguous type. By using a fully qualified type name like java.util.Date you can be sure it won't be confused with some other Date class in a different package. However if your import statement includes java.util.* or java.util.Date already, then just saying Date will be unambiguous enough and the compiler will know which Date you mean.

Upvotes: 5

Related Questions