-
Enhancement
-
Resolution: Duplicate
-
P4
-
None
-
1.2.0
-
generic
-
generic
Name: diC59631 Date: 01/28/99
Some days ago I requested a setTimeInMillis(long) in the class
Calendar, after getting the answer, you don't want to do it, I
have now a suggestion, that let's the abstraction of using
only Date objects to set the value in Calendar objects, but
also minimizes the number of allocated Date-Instances.
The Calendar class has the following methods, that are interesting in
changeing or setting it's value:
public final java.util.Data getTime()
to retrieve the actual value
and
public final void setTime(java.util.Date)
to set a new value
Now if I heavely use a Calendar object, i.e. I implement a tool
like a scheduler, I quickly will have tousends of Date-Objects in
memory, which I use only to transport a long value to set
or retreave the actual value in the Calendar object. May be
java has a garbage collector, but I guess the better
approche would be to avoid unneccessary objects in memory.
My suggestion would be to implement a suplementary method
public final java.util.Date getTime(java.util.Date)
this method doesn't allocate any new Date objects, it
just sets the internal value and returns it.
So my tool has only one Date-Object, which it uses for setting or
retreaving the actual value from calendar-object.
Here is an exemple:
public void main(String[] args)
{
Calendar c = Calendar.getInstance();
for (int i = 0, i < 1000, i++) {
System.out.println(c.getTime()); // here will be allocated a Date object everytime!!
}
}
my approche
public void main(String[] args)
{
Calendar c = Calendar.getInstance();
Date transferDate = new Date();
for (int i = 0, i < 1000, i++) {
System.out.println(c.getTime(transferDate)); // only one Date-object allocated!!
}
}
you can see the difference, actualy I would have to allocated 1000
date objects in memory, and recycling the Date would save 999 objects in memory.
(Review ID: 53331)
======================================================================
- duplicates
-
JDK-4243802 RFE: need way to set the date of a calendar without a Date object
-
- Resolved
-