“Cannot subclass the final class” error, but the class is not final [closed]
Here is my code:
package basic;
public abstract class Entity {}
package characters;
import basic.Entity;
public abstract class Character extends Entity {}
package player;
public class Player extends Character {}
I am getting the
The type
Player
cannot subclass thefinal class Character
.
but I checked a million times and I am yet to use final
all but ONCE in my project. What gives?
java inheritance package final-class
closed as off-topic by Nic Hartley, Mooing Duck, Boris the Spider, Amit Joki, Matsemann Dec 18 '18 at 8:54
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Nic Hartley, Mooing Duck, Boris the Spider, Amit Joki, Matsemann
If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
Here is my code:
package basic;
public abstract class Entity {}
package characters;
import basic.Entity;
public abstract class Character extends Entity {}
package player;
public class Player extends Character {}
I am getting the
The type
Player
cannot subclass thefinal class Character
.
but I checked a million times and I am yet to use final
all but ONCE in my project. What gives?
java inheritance package final-class
closed as off-topic by Nic Hartley, Mooing Duck, Boris the Spider, Amit Joki, Matsemann Dec 18 '18 at 8:54
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Nic Hartley, Mooing Duck, Boris the Spider, Amit Joki, Matsemann
If this question can be reworded to fit the rules in the help center, please edit the question.
12
The answer is already given. Here's a tip how to find it out using your IDE (e.g. Eclipse). Place the mouse over the ´Character´ word, and it'll show you that it'sjava.lang.Character
and notcharacters.Character
.
– Ralf Kleberhoff
Dec 14 '18 at 17:14
add a comment |
Here is my code:
package basic;
public abstract class Entity {}
package characters;
import basic.Entity;
public abstract class Character extends Entity {}
package player;
public class Player extends Character {}
I am getting the
The type
Player
cannot subclass thefinal class Character
.
but I checked a million times and I am yet to use final
all but ONCE in my project. What gives?
java inheritance package final-class
Here is my code:
package basic;
public abstract class Entity {}
package characters;
import basic.Entity;
public abstract class Character extends Entity {}
package player;
public class Player extends Character {}
I am getting the
The type
Player
cannot subclass thefinal class Character
.
but I checked a million times and I am yet to use final
all but ONCE in my project. What gives?
java inheritance package final-class
java inheritance package final-class
edited Dec 15 '18 at 9:19
Andrew Tobilko
27.4k104285
27.4k104285
asked Dec 14 '18 at 12:27
FletcherFletcher
34429
34429
closed as off-topic by Nic Hartley, Mooing Duck, Boris the Spider, Amit Joki, Matsemann Dec 18 '18 at 8:54
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Nic Hartley, Mooing Duck, Boris the Spider, Amit Joki, Matsemann
If this question can be reworded to fit the rules in the help center, please edit the question.
closed as off-topic by Nic Hartley, Mooing Duck, Boris the Spider, Amit Joki, Matsemann Dec 18 '18 at 8:54
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – Nic Hartley, Mooing Duck, Boris the Spider, Amit Joki, Matsemann
If this question can be reworded to fit the rules in the help center, please edit the question.
12
The answer is already given. Here's a tip how to find it out using your IDE (e.g. Eclipse). Place the mouse over the ´Character´ word, and it'll show you that it'sjava.lang.Character
and notcharacters.Character
.
– Ralf Kleberhoff
Dec 14 '18 at 17:14
add a comment |
12
The answer is already given. Here's a tip how to find it out using your IDE (e.g. Eclipse). Place the mouse over the ´Character´ word, and it'll show you that it'sjava.lang.Character
and notcharacters.Character
.
– Ralf Kleberhoff
Dec 14 '18 at 17:14
12
12
The answer is already given. Here's a tip how to find it out using your IDE (e.g. Eclipse). Place the mouse over the ´Character´ word, and it'll show you that it's
java.lang.Character
and not characters.Character
.– Ralf Kleberhoff
Dec 14 '18 at 17:14
The answer is already given. Here's a tip how to find it out using your IDE (e.g. Eclipse). Place the mouse over the ´Character´ word, and it'll show you that it's
java.lang.Character
and not characters.Character
.– Ralf Kleberhoff
Dec 14 '18 at 17:14
add a comment |
4 Answers
4
active
oldest
votes
You are extending java.lang.Character
(which does not need an import, as it comes from java.lang
).
Insert import characters.Character
into your Player
code.
Reference: using package members:
For convenience, the Java compiler automatically imports two entire packages for each source file: (1) the java.lang package and (2) the current package (the package for the current file).
19
Instead, rename the customCharacter
class.
– chrylis
Dec 15 '18 at 7:14
add a comment |
Character is a class of java.lang (the wrapper class of "char").
you have to import characters.Character in your Player class
package player;
import characters.Character
public class Player extends Character {
}
12
A better suggestion would be to avoid doubling the names of default library classes in your code-base altogether. Treat "Character" just as you would the keyword "char" since that's what it stands in for anyhow. I'd say rename the "Character" class to "Avatar", "Entity", "Person" or something else that won't cause any confusion with existing default classes.
– Darrel Hoffman
Dec 14 '18 at 18:39
add a comment |
In this case, I strongly recommend using the fully qualified name of the Character
class in the extends
clause.
public class Player extends characters.Character {}
Experienced Java developers know that java.lang.Character
is final
and can't thereby be extended. By writing class Player extends Character
, you would probably make them nonplussed.
Every compilation unit implicitly imports every public type name declared in the predefined package
java.lang
, as if the declarationimport java.lang.*;
appeared at the beginning of each compilation unit immediately after any package declaration. As a result, the names of all those types are available as simple names in every compilation unit.
Java 11 Specification > 7. Packages and Modules > 7.3. Compilation Units
Of course, it would be more reasonable to pick up a name that doesn't collide with the classes from the standard java.lang
package (like Person
, or GameCharacter
).
add a comment |
Character is a final class as defined in Java Docs:
public final class Character
extends Object
implements Serializable, Comparable<Character>
so it cannot be sub-classed.
You are getting error from this Character class, which is being implicitly imported. Beware!.
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
You are extending java.lang.Character
(which does not need an import, as it comes from java.lang
).
Insert import characters.Character
into your Player
code.
Reference: using package members:
For convenience, the Java compiler automatically imports two entire packages for each source file: (1) the java.lang package and (2) the current package (the package for the current file).
19
Instead, rename the customCharacter
class.
– chrylis
Dec 15 '18 at 7:14
add a comment |
You are extending java.lang.Character
(which does not need an import, as it comes from java.lang
).
Insert import characters.Character
into your Player
code.
Reference: using package members:
For convenience, the Java compiler automatically imports two entire packages for each source file: (1) the java.lang package and (2) the current package (the package for the current file).
19
Instead, rename the customCharacter
class.
– chrylis
Dec 15 '18 at 7:14
add a comment |
You are extending java.lang.Character
(which does not need an import, as it comes from java.lang
).
Insert import characters.Character
into your Player
code.
Reference: using package members:
For convenience, the Java compiler automatically imports two entire packages for each source file: (1) the java.lang package and (2) the current package (the package for the current file).
You are extending java.lang.Character
(which does not need an import, as it comes from java.lang
).
Insert import characters.Character
into your Player
code.
Reference: using package members:
For convenience, the Java compiler automatically imports two entire packages for each source file: (1) the java.lang package and (2) the current package (the package for the current file).
answered Dec 14 '18 at 12:29
Adam KotwasinskiAdam Kotwasinski
2,543827
2,543827
19
Instead, rename the customCharacter
class.
– chrylis
Dec 15 '18 at 7:14
add a comment |
19
Instead, rename the customCharacter
class.
– chrylis
Dec 15 '18 at 7:14
19
19
Instead, rename the custom
Character
class.– chrylis
Dec 15 '18 at 7:14
Instead, rename the custom
Character
class.– chrylis
Dec 15 '18 at 7:14
add a comment |
Character is a class of java.lang (the wrapper class of "char").
you have to import characters.Character in your Player class
package player;
import characters.Character
public class Player extends Character {
}
12
A better suggestion would be to avoid doubling the names of default library classes in your code-base altogether. Treat "Character" just as you would the keyword "char" since that's what it stands in for anyhow. I'd say rename the "Character" class to "Avatar", "Entity", "Person" or something else that won't cause any confusion with existing default classes.
– Darrel Hoffman
Dec 14 '18 at 18:39
add a comment |
Character is a class of java.lang (the wrapper class of "char").
you have to import characters.Character in your Player class
package player;
import characters.Character
public class Player extends Character {
}
12
A better suggestion would be to avoid doubling the names of default library classes in your code-base altogether. Treat "Character" just as you would the keyword "char" since that's what it stands in for anyhow. I'd say rename the "Character" class to "Avatar", "Entity", "Person" or something else that won't cause any confusion with existing default classes.
– Darrel Hoffman
Dec 14 '18 at 18:39
add a comment |
Character is a class of java.lang (the wrapper class of "char").
you have to import characters.Character in your Player class
package player;
import characters.Character
public class Player extends Character {
}
Character is a class of java.lang (the wrapper class of "char").
you have to import characters.Character in your Player class
package player;
import characters.Character
public class Player extends Character {
}
answered Dec 14 '18 at 12:30
ChrisChris
35313
35313
12
A better suggestion would be to avoid doubling the names of default library classes in your code-base altogether. Treat "Character" just as you would the keyword "char" since that's what it stands in for anyhow. I'd say rename the "Character" class to "Avatar", "Entity", "Person" or something else that won't cause any confusion with existing default classes.
– Darrel Hoffman
Dec 14 '18 at 18:39
add a comment |
12
A better suggestion would be to avoid doubling the names of default library classes in your code-base altogether. Treat "Character" just as you would the keyword "char" since that's what it stands in for anyhow. I'd say rename the "Character" class to "Avatar", "Entity", "Person" or something else that won't cause any confusion with existing default classes.
– Darrel Hoffman
Dec 14 '18 at 18:39
12
12
A better suggestion would be to avoid doubling the names of default library classes in your code-base altogether. Treat "Character" just as you would the keyword "char" since that's what it stands in for anyhow. I'd say rename the "Character" class to "Avatar", "Entity", "Person" or something else that won't cause any confusion with existing default classes.
– Darrel Hoffman
Dec 14 '18 at 18:39
A better suggestion would be to avoid doubling the names of default library classes in your code-base altogether. Treat "Character" just as you would the keyword "char" since that's what it stands in for anyhow. I'd say rename the "Character" class to "Avatar", "Entity", "Person" or something else that won't cause any confusion with existing default classes.
– Darrel Hoffman
Dec 14 '18 at 18:39
add a comment |
In this case, I strongly recommend using the fully qualified name of the Character
class in the extends
clause.
public class Player extends characters.Character {}
Experienced Java developers know that java.lang.Character
is final
and can't thereby be extended. By writing class Player extends Character
, you would probably make them nonplussed.
Every compilation unit implicitly imports every public type name declared in the predefined package
java.lang
, as if the declarationimport java.lang.*;
appeared at the beginning of each compilation unit immediately after any package declaration. As a result, the names of all those types are available as simple names in every compilation unit.
Java 11 Specification > 7. Packages and Modules > 7.3. Compilation Units
Of course, it would be more reasonable to pick up a name that doesn't collide with the classes from the standard java.lang
package (like Person
, or GameCharacter
).
add a comment |
In this case, I strongly recommend using the fully qualified name of the Character
class in the extends
clause.
public class Player extends characters.Character {}
Experienced Java developers know that java.lang.Character
is final
and can't thereby be extended. By writing class Player extends Character
, you would probably make them nonplussed.
Every compilation unit implicitly imports every public type name declared in the predefined package
java.lang
, as if the declarationimport java.lang.*;
appeared at the beginning of each compilation unit immediately after any package declaration. As a result, the names of all those types are available as simple names in every compilation unit.
Java 11 Specification > 7. Packages and Modules > 7.3. Compilation Units
Of course, it would be more reasonable to pick up a name that doesn't collide with the classes from the standard java.lang
package (like Person
, or GameCharacter
).
add a comment |
In this case, I strongly recommend using the fully qualified name of the Character
class in the extends
clause.
public class Player extends characters.Character {}
Experienced Java developers know that java.lang.Character
is final
and can't thereby be extended. By writing class Player extends Character
, you would probably make them nonplussed.
Every compilation unit implicitly imports every public type name declared in the predefined package
java.lang
, as if the declarationimport java.lang.*;
appeared at the beginning of each compilation unit immediately after any package declaration. As a result, the names of all those types are available as simple names in every compilation unit.
Java 11 Specification > 7. Packages and Modules > 7.3. Compilation Units
Of course, it would be more reasonable to pick up a name that doesn't collide with the classes from the standard java.lang
package (like Person
, or GameCharacter
).
In this case, I strongly recommend using the fully qualified name of the Character
class in the extends
clause.
public class Player extends characters.Character {}
Experienced Java developers know that java.lang.Character
is final
and can't thereby be extended. By writing class Player extends Character
, you would probably make them nonplussed.
Every compilation unit implicitly imports every public type name declared in the predefined package
java.lang
, as if the declarationimport java.lang.*;
appeared at the beginning of each compilation unit immediately after any package declaration. As a result, the names of all those types are available as simple names in every compilation unit.
Java 11 Specification > 7. Packages and Modules > 7.3. Compilation Units
Of course, it would be more reasonable to pick up a name that doesn't collide with the classes from the standard java.lang
package (like Person
, or GameCharacter
).
edited Dec 15 '18 at 9:02
answered Dec 14 '18 at 13:44
Andrew TobilkoAndrew Tobilko
27.4k104285
27.4k104285
add a comment |
add a comment |
Character is a final class as defined in Java Docs:
public final class Character
extends Object
implements Serializable, Comparable<Character>
so it cannot be sub-classed.
You are getting error from this Character class, which is being implicitly imported. Beware!.
add a comment |
Character is a final class as defined in Java Docs:
public final class Character
extends Object
implements Serializable, Comparable<Character>
so it cannot be sub-classed.
You are getting error from this Character class, which is being implicitly imported. Beware!.
add a comment |
Character is a final class as defined in Java Docs:
public final class Character
extends Object
implements Serializable, Comparable<Character>
so it cannot be sub-classed.
You are getting error from this Character class, which is being implicitly imported. Beware!.
Character is a final class as defined in Java Docs:
public final class Character
extends Object
implements Serializable, Comparable<Character>
so it cannot be sub-classed.
You are getting error from this Character class, which is being implicitly imported. Beware!.
edited Dec 14 '18 at 13:43
Andrei Suvorkov
4,1674929
4,1674929
answered Dec 14 '18 at 12:36
JabonggJabongg
555415
555415
add a comment |
add a comment |
12
The answer is already given. Here's a tip how to find it out using your IDE (e.g. Eclipse). Place the mouse over the ´Character´ word, and it'll show you that it's
java.lang.Character
and notcharacters.Character
.– Ralf Kleberhoff
Dec 14 '18 at 17:14