What level will you be teaching Java?
Now, in C# numbers are objects- they are basically references to objects. Java may eventually follow the C# route here.
Boxing and unboxing enable value types to be treated as objects. Value types, including both struct types and built-in types, such as int, can be converted to and from the type object.
An unboxing operation consists of first checking that the object instance is a boxed value of the given value-type, and then copying the value out of the instance.
Referring to the imaginary boxing class described in the previous section, an unboxing conversion of an object box to a value-type T consists of executing the expression ((T_Box)box).value. Thus, the statements
object box = 123;
int i = (int)box;
conceptually correspond to
object box = new int_Box(123);
int i = ((int_Box)box).value;
For an unboxing conversion to a given value-type to succeed at run-time, the value of the source operand must be a reference to an object that was previously created by boxing a value of that value-type.
The autoboxing code you're showing is a similar approach to teaching Java. I like it, and I predict that we'll be seeing more and more of that as time goes on.
What I was trying to say about C# was that simple types like-int is actually an alias for the System.Int32 type in the .net CTS. Thus, each of the intrinsic or simple data types in C# are an alias- for a class in the System namespace.
This is not how primatives behave in Java- What are the equivalent alias for Java primatives. I would not consider Wrapper classes that.
Now, as for auto boxing- I am not saying it is wrong. It is not commonly procticed and used intro to Java programming course- when dealing with simple data types.
What text are you going to use for the course? I think this is important in an intro course as well.
The first half of the course uses Alice, so we're using "Learning to Program with Alice" by Wanda Dann. We are still considering the text for the second half (Java specific) of the course. I'm not aware of any book that uses the auto-boxing/unboxing approach I suggest at the begining of this thread for simple types like ints.[/qoute]
Yep, your right,
Liang, Deitel, Savitch, Horstmann, Gaddis, Koffman and there new 5.0 books do have auto boxing but not the way you want to do it.
You may have to supplement the material. Hmm. sounds like a good publishing oppportunity.