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

376 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 best solutions below

1
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
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.