Graphics2D
is a class which inherits from Graphics
- the same way that "human" is a class of "biped", and it is true that all humans are bipeds but it is not true that all bipeds are humans.
java.awt.Graphics
dates to the earliest days of Java and was not very sophisticated. Waphen Swing and Java2D were created, Graphics2D
was created as a subclass of Graphics
so that old code would work - backwards compatibility was a religion at Sun (and not a bad one).
JComponent
and other Swing classes inherit from java.awt.Component
, which used the old API. To make it easy for people to migrate from AWT to Swing without making any changes except the superclass, Swing kept the signature of taking a Graphics
rather than a Graphics2D
.
It is well documented that in Swing, the Graphics passed to paint(Graphics)
will always be a Graphics2D
, so you do not need an alternate code-path to handle the case that it is not.