Java Reference
In-Depth Information
Casting an
int
to an
Integer
is called boxing and requires an invocation of the
Integer
.valueOf()
method:
invokestaticjava/lang/Integer.valueOf:(I)Ljava/lang/Integer;
Casting an
Integer
to an
int
is called unboxing and requires an invocation of the
Integer.intValue()
method:
invokevirtualjava/lang/Integer.intValue:()I
Certain casts, from one primitive type to another, require that a special instruction be
executed. For example, the
i2c
instruction converts an
int
to a
char
. There is a
Converter
defined for each valid conversion in j--.
5.8 Further Readings
[Lindholm and Yellin, 1999] is the authoritative reference for the JVM and its instruction
set; Chapter 7 in that text discusses some of the issues in compiling a high-level language
such as Java to the JVM.
An excellent introduction to compiling Microsoft's
R
.NET Common Language Runtime
(CLR) is [Gough and Gough, 2001].
[Strachey, 2000] introduces the notion of l-values and r-values.
A good introduction to the behavior of Java generics|one of our exercises below|
is [Bracha, 2004].
5.9 Exercises
Exercise 5.1. Add interfaces (as a type declaration) to j--. Make any changes that are
necessary to classes and class declarations for accommodating interfaces. Test your imple-
mentation thoroughly.
An interface defines a type that obeys a contract. Declare a variable to be of an interface
type and you can be sure that it will refer to objects that support certain behaviors. Any
class that implements the interface must support those same behaviors. Think of an interface
as a purely abstract class.
From the point of view of analysis, interfaces have all sorts of rules that must be enforced.
Method
analyze()
, in both
JInterfaceDeclaration
, and
JClassDeclaration
is where
most of these rules may be enforced. These rules include
1. Although an interface may have
public
,
protected
, or
private
modifiers, only
public
is meaningful for interfaces not nested within other classes.
2. The compiler must also allow the modifiers
abstract
,
static
, and
strictfp
. The
abstract
modifier is redundant (as all interfaces are abstract) but the compiler must
allow it. The
static
modifier has meaning only for member (nested) interfaces. The
strictfp
modifier has meaning if and only if one is supporting (
float
or
double
)
floating-point arithmetic.
Search WWH ::
Custom Search