Java 包装构造函数获取NumberFormatException:

Java 包装构造函数获取NumberFormatException:,java,wrapper,numberformatexception,Java,Wrapper,Numberformatexception,在上面的代码中,我没有得到任何异常。但是下面的代码是我得到的 NumberFormatException: Float f1 = new Float("12.6f"); 我知道除了Character之外的所有包装器类都提供了两个构造函数 Long l1= new Long("200L"); 那为什么我会有例外呢 Integer i1 = new Integer(42); //Primitive Integer i2 = new Integer("42"); // String Float

在上面的代码中,我没有得到任何异常。但是下面的代码是我得到的
NumberFormatException

Float f1 = new Float("12.6f");
我知道除了Character之外的所有包装器类都提供了两个构造函数

Long l1= new Long("200L"); 
那为什么我会有例外呢

Integer i1 = new Integer(42); //Primitive
Integer i2 = new Integer("42"); // String
Float f1 = new Float(3.14f); //Primitive
Float f2 = new Float("3.14f"); // String
为什么没有

Long l1= new Long("200L");  

检查构造函数的文档

Long l1= new Long("200L"); 
对于
Long
,它遵从
Long.parseLong
,它不接受以
L
结尾的字符串。然而,
Float
具有不同的解析行为,这取决于它是否提供了
3.14d
3.14f
,因此它们都是特定构造函数的有效输入