Skip to main content

Re: Email proposal to the core-libs-dev@openjdk.java.net

  • From: Martin Desruisseaux < >
  • To:
  • Subject: Re: Email proposal to the
  • Date: Tue, 21 Oct 2014 17:24:01 +0900
  • Organization: Geomatys

Le 21/10/14 04:59, Otávio Gonçalves de Santana a écrit :
> This way, I keep may do cast and I could have the same semantic
> problem, but with more code.
> Unit<Speed> kmh = (Unit<Speed>)SIPrefix.KILO(SI.METRE).divide(UCUM.HOUR);

This cast is unsafe. The user get a "unsafe cast" warning from the
compiler, which is true. By contrast Jean-Marie's approach:


> Unit<Speed> kmh =
> SIPrefix.KILO(SI.METRE).divide(UCUM.HOUR).asType(Speed.class);

Is safe.

Otavio, are you aware of the following java.lang.Class method?

Class.asSubclass(Class<U>)
<http://docs.oracle.com/javase/8/docs/api/java/lang/Class.html#asSubclass-java.lang.Class->
-  Given Class<?> classOfUnknownType;

  * Class<Number> n = (Class<Number>) classOfUnknownType  is unsafe.
  * Class<Number> n = classOfUnknownType.asSubtype(Number.class)  is
    safe and the recommended substitute to above cast.

Class.asSubclass(Class) addresses basically the same problem that our
Unit.asType(Class) method does. I'm not aware of any better safe solution.

    Martin



Email proposal to the

Martin Desruisseaux 10/19/2014

Re: Email proposal to the

Otávio Gonçalves de Santana 10/19/2014

Re: Email proposal to the

Martin Desruisseaux 10/20/2014

Re: Email proposal to the

Otávio Gonçalves de Santana 10/20/2014

Re: Email proposal to the

Werner Keil 10/20/2014

Re: Email proposal to the

Martin Desruisseaux 10/20/2014

Re: Email proposal to the

Otávio Gonçalves de Santana 10/20/2014

Re: Email proposal to the

Werner Keil 10/20/2014

Re: Email proposal to the

Otávio Gonçalves de Santana 10/20/2014

Re: Email proposal to the

Werner Keil 10/20/2014

Re: Email proposal to the

Martin Desruisseaux 10/21/2014

Re: Email proposal to the

Martin Desruisseaux 10/21/2014

Re: Email proposal to the

Werner Keil 10/21/2014

Re: Email proposal to the

Martin Desruisseaux 10/21/2014

Re: Email proposal to the

Werner Keil 10/21/2014

Re: Email proposal to the

Otávio Gonçalves de Santana 10/21/2014

Re: Email proposal to the

Werner Keil 10/21/2014

Re: Email proposal to the

Martin Desruisseaux 10/21/2014

Re: Email proposal to the

Werner Keil 10/21/2014

Re: Email proposal to the

Martin Desruisseaux 10/21/2014

Re: Email proposal to the

Werner Keil 10/21/2014
 
 
Close
loading
Please Confirm
Close