J
J Leonard
Here is a question about the use of casts. It isn't so much about the
syntax of casts but about their "under the hood" meaning.
For example, when an applet needs to be re-displayed the JVM calls the
applet "paint" method and passes to it a graphics object. Standard
practice is to cast this Graphics object to type Graphics2D and use
it.
I'm trying to understand how this can work. My concept of what is
happening goes like this: the JVM instantiates a Graphics object and
associates it with the drawing surface, a Container or some such.
When the applet needs to be redrawn the JVM calls the applets paint
method and the Graphics object is passed by reference to the method.
I'm coming to Java from C. My understanding of casts is that they
cause the compiler to interpret an object differently. They don't
change the object. Casting a Graphics object to type Graphics2D also
doesn't instantiate a Graphics2D object. If the object created by the
JVM isn't actually a Graphics2D object I don't see how this could
work.
Perhaps JVM 1.2 and later actually instantiate Graphics2D objects in
this case but the argument passed to paint is still considered to be a
Graphics object by default, for some reason?
Thanks for your help,
J Leonard
syntax of casts but about their "under the hood" meaning.
For example, when an applet needs to be re-displayed the JVM calls the
applet "paint" method and passes to it a graphics object. Standard
practice is to cast this Graphics object to type Graphics2D and use
it.
I'm trying to understand how this can work. My concept of what is
happening goes like this: the JVM instantiates a Graphics object and
associates it with the drawing surface, a Container or some such.
When the applet needs to be redrawn the JVM calls the applets paint
method and the Graphics object is passed by reference to the method.
I'm coming to Java from C. My understanding of casts is that they
cause the compiler to interpret an object differently. They don't
change the object. Casting a Graphics object to type Graphics2D also
doesn't instantiate a Graphics2D object. If the object created by the
JVM isn't actually a Graphics2D object I don't see how this could
work.
Perhaps JVM 1.2 and later actually instantiate Graphics2D objects in
this case but the argument passed to paint is still considered to be a
Graphics object by default, for some reason?
Thanks for your help,
J Leonard