groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dinko Srkoč <dinko.sr...@gmail.com>
Subject Re: Super Confused About Java vs Groovy Date() and deprecation
Date Sun, 10 Jan 2016 15:50:20 GMT
On 10 January 2016 at 05:41, Gerald Wiltse <jerrywiltse@gmail.com> wrote:
> I'm sure this is old topic, but I can't find clear answer. IT's about
> Date(), but i suppose it's true for anything "Java" which Groovy has
> decorated.

Actually, it's mostly about Java, not much Groovy here.

>
> Apparently, Java Date() is ancient, disliked, and now a bunch of the
> fundamental Java Date() stuff is all "deprecated".  Fortunately, Groovys new
> Date().parse(string,string) constructor still works for me.  But, everything

Groovy's `Date.parse` is a static method, so no need to instantiate
`Date` to use `parse()` ... This pretty much concludes Groovy's
involvement here. ;-)

> I try to do with my date object now says deprectated.  It gives me all the
> good code completion, and shows that it's suggesting Groovy methods, but
> when I implement it puts a strikethrough, and says of course...
>
> setYear
>
> @Deprecated
> public void setYear(int year)
>
> Deprecated. As of JDK version 1.1, replaced by Calendar.set(Calendar.YEAR,
> year + 1900).
>
> 1.  I want to color inside the lines, so should I move toward using all
> Calendar objects and methods and completely avoid using Date() on new
> projects?  It's no problem, I just don't see that clearly stated anywhere in
> the Groovy docs.

The links that Thibault provided are relevant here.

It is not stated in the Groovy docs because those are not Groovy's
classes, they're Java's. Groovy does provide some extensions, but that
is just to make your life easier if you happen to use that particular
API.

You should probably use java.time.* if you're on Java 8, otherwise
Joda-Time library. Date & Calendar is always here if all else fails.

>
> 2.  OR... are Groovy date methods alive and well and somehow I can tell
> eclipse to stop associated with the old Java classes when Groovy ones are
> present?

Eclipse is right to mark those methods as deprecated because they are.
Groovy cannot hide them.

>
> If this is an eclipse only issue, then I'm sorry.

It is not, nothing to be sorry about. :-) Every self-respecting IDE
should to the same (and indeed they do).

Cheers,
Dinko

>
> Thanks again!
>
> Regards,
> Jerry
>
>
> Gerald R. Wiltse
> jerrywiltse@gmail.com
>

Mime
View raw message