java - No autoboxing for BigInteger? -


while fixing code this question, realized autoboxing doesn't work types. code compiles:

integer y = 3; 

but doing same biginteger doesn't compile:

biginteger x = 3; 

-> "type mismatch: cannot convert int biginteger"

is there no autoboxing biginteger? if not, rule types supporting autoboxing , why isn't biginteger included?

first of all, note biginteger part of java.math , not java.lang, , not receive special treatment language. of boxed types in java.lang , java language might treat them specially. such consideration can include boxing, strings in constant pools, class objects living in specialized areas of memory, etc.

secondly, reference document called java language specification (or jls short) describes precisely:

boxing conversion converts expressions of primitive type corresponding expressions of reference type. specifically, following 9 conversions called boxing conversions:

  • from type boolean type boolean

  • from type byte type byte

  • from type short type short

  • from type char type character

  • from type int type integer

  • from type long type long

  • from type float type float

  • from type double type double

  • from null type null type

source

however, there request allow autoboxing biginteger , giving special meaning various mathematical operators when applied biginteger objects.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -