Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

FUCK JAVA

Name: CHUMPY CS STUDENT 2010-12-07 20:53

public class Player extends Piece { ... }
/* ... */
public static Piece inputPiece() { ... }
/* ... */

Player playa = inputPiece();

ChumpyProgram.java:43: incompatible types
found   : Piece
required: Player


So what the fuck is the point of inheritance if you can't do that?

Name: Anonymous 2010-12-07 21:31

>>5
Well, a Player has all the properties and methods of a Piece. Why shouldn't a cast work? I know it's adding extra shit but it shouldn't pussy out at that. It's not "C with memory protection".
Upcasting works apparently.
I just wanted a generic input method so I didn't have to write identical code for both Piece and Treasure (that also inherits from Piece).

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List