简体   繁体   中英

Whether double wrapper class supports float argument?

As per Java tutorials, Double Wrapper class supports String and Double as argument.

But I am able to use float argument. Check below code. Can some clarify this?

class test {

public static void main(String[] args)
{

    Double d=new Double(10.5f);

    Double d1=new Double("10.5f");

    System.out.println(d);  
    System.out.println(d1);

}   

}

Output:

10.5 10.5

Java automatically promotes float to double if needed (it's called a widening conversion).

See the JLS for details

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM