“Cannot subclass the final class” error, but class is not final
up vote
9
down vote
favorite
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 the final class Character" but I checked a million times and I am yet to use final
all but ONCE in my project. What gives?
java
add a comment |
up vote
9
down vote
favorite
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 the final class Character" but I checked a million times and I am yet to use final
all but ONCE in my project. What gives?
java
add a comment |
up vote
9
down vote
favorite
up vote
9
down vote
favorite
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 the final class Character" but I checked a million times and I am yet to use final
all but ONCE in my project. What gives?
java
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 the final class Character" but I checked a million times and I am yet to use final
all but ONCE in my project. What gives?
java
java
asked 1 hour ago
Fletcher
704
704
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
up vote
24
down vote
accepted
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).
add a comment |
up vote
6
down vote
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 {
}
add a comment |
up vote
4
down vote
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 |
up vote
1
down vote
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 thus can't be extended. By writing class Player extends Character
, you would probably make them nonplussed.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53779769%2fcannot-subclass-the-final-class-error-but-class-is-not-final%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
24
down vote
accepted
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).
add a comment |
up vote
24
down vote
accepted
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).
add a comment |
up vote
24
down vote
accepted
up vote
24
down vote
accepted
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 1 hour ago
Adam Kotwasinski
2,218626
2,218626
add a comment |
add a comment |
up vote
6
down vote
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 {
}
add a comment |
up vote
6
down vote
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 {
}
add a comment |
up vote
6
down vote
up vote
6
down vote
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 1 hour ago
Chris
8810
8810
add a comment |
add a comment |
up vote
4
down vote
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 |
up vote
4
down vote
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 |
up vote
4
down vote
up vote
4
down vote
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 26 mins ago
Andrei Suvorkov
4,1404929
4,1404929
answered 1 hour ago
Jangbahadur Patel
188211
188211
add a comment |
add a comment |
up vote
1
down vote
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 thus can't be extended. By writing class Player extends Character
, you would probably make them nonplussed.
add a comment |
up vote
1
down vote
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 thus can't be extended. By writing class Player extends Character
, you would probably make them nonplussed.
add a comment |
up vote
1
down vote
up vote
1
down vote
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 thus can't be extended. By writing class Player extends Character
, you would probably make them nonplussed.
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 thus can't be extended. By writing class Player extends Character
, you would probably make them nonplussed.
edited 1 min ago
answered 25 mins ago
Andrew Tobilko
24.7k84182
24.7k84182
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53779769%2fcannot-subclass-the-final-class-error-but-class-is-not-final%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown