this is the code i was looking at.Its about how to use JTextPane and related swing text Components along with actions and keymaps.
my question is that in this part
textPane = new JTextPane();
textPane.setCaretPosition(0);
textPane.setMargin(new Insets(5, 5, 5, 5));
StyledDocument styledDoc = textPane.getStyledDocument();
if (styledDoc instanceof AbstractDocument) {
doc = (AbstractDocument) styledDoc;
// doc.setDocumentFilter(new DocumentSizeFilter(MAX_CHARACTERS));// DocumentSizeFilter doesnt work , eclipse giving errors
} else {
System.err
.println("Text pane's document isn't an AbstractDocument!");
System.exit(-1);
}
in the lines doc = (AbstractDocument) styledDoc;
, does doc
and styledDoc
point to the same location in the heap ? or does the casting create a new memory-space / object-instance pointed to by doc
.
a related question that was going on in my head was that :
if styledDoc is an instanceof AbstractDocument , why do we need the cast ?