“Cannot subclass the final class” error, but class is not final











up vote
9
down vote

favorite
1












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?










share|improve this question


























    up vote
    9
    down vote

    favorite
    1












    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?










    share|improve this question
























      up vote
      9
      down vote

      favorite
      1









      up vote
      9
      down vote

      favorite
      1






      1





      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?










      share|improve this question













      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






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 1 hour ago









      Fletcher

      704




      704
























          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).







          share|improve this answer




























            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 {

            }





            share|improve this answer




























              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!.






              share|improve this answer






























                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.






                share|improve this answer























                  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
                  });


                  }
                  });














                  draft saved

                  draft discarded


















                  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).







                  share|improve this answer

























                    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).







                    share|improve this answer























                      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).







                      share|improve this answer












                      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).








                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered 1 hour ago









                      Adam Kotwasinski

                      2,218626




                      2,218626
























                          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 {

                          }





                          share|improve this answer

























                            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 {

                            }





                            share|improve this answer























                              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 {

                              }





                              share|improve this answer












                              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 {

                              }






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered 1 hour ago









                              Chris

                              8810




                              8810






















                                  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!.






                                  share|improve this answer



























                                    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!.






                                    share|improve this answer

























                                      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!.






                                      share|improve this answer














                                      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!.







                                      share|improve this answer














                                      share|improve this answer



                                      share|improve this answer








                                      edited 26 mins ago









                                      Andrei Suvorkov

                                      4,1404929




                                      4,1404929










                                      answered 1 hour ago









                                      Jangbahadur Patel

                                      188211




                                      188211






















                                          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.






                                          share|improve this answer



























                                            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.






                                            share|improve this answer

























                                              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.






                                              share|improve this answer














                                              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.







                                              share|improve this answer














                                              share|improve this answer



                                              share|improve this answer








                                              edited 1 min ago

























                                              answered 25 mins ago









                                              Andrew Tobilko

                                              24.7k84182




                                              24.7k84182






























                                                  draft saved

                                                  draft discarded




















































                                                  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.




                                                  draft saved


                                                  draft discarded














                                                  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





















































                                                  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







                                                  Popular posts from this blog

                                                  flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror

                                                  Mangá

                                                  Eduardo VII do Reino Unido