What is the difference between autoboxing and coercion? [closed]
Asked Answered
L

3

3

I program in Java, C and Python.

The rule for automatic coercions among arithmetic types have been augmented to handle the richer set of types

Source: "The C Programming Language"

But what does "coercion" mean? The answers say it's like type conversion and implicit casts and implicit type conversions and called autoboxing where I read it.

What is the difference between autoboxing and coercion?

Lawsuit answered 18/6, 2012 at 15:34 Comment(2)
First result on google for programming coercion.Goliath
auto-boxing is something completely different, and wasn't in the original question. Specifically, auto-boxing is a Java feature that (implicitly) wraps a primitive value into its "Object" variety, e.g. an int into an Integer. The reverse can happen too, e.g. an Integer can be automatically unboxed into an int value.Aircraft
A
13

Coercion is another name for an implicit type cast, i.e. one mandated by the language rules, and not explicitly added by the programmer.

Aircraft answered 18/6, 2012 at 15:37 Comment(0)
B
6

Coercion refers to "type coercion". In other words, you add a variable of type Integer to a Float, the Integer will be coerced to Float, and the numbers added together.

Borrow answered 18/6, 2012 at 15:36 Comment(0)
A
0

Coercion is the process of changing one data type into another. http://en.wikipedia.org/wiki/Type_conversion

Alikee answered 18/6, 2012 at 15:36 Comment(1)
Do state the difference between the two.Dubuffet

© 2022 - 2024 — McMap. All rights reserved.