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

372 views Asked by At

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?

2

There are 2 answers

1
Always Learning On BEST ANSWER

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.

0
4nti On

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.