If I have a java class which is
            package-private (declared with "class", not "public class"), there is really no
            difference if the methods inside are declared public or protected or package-private,
            right? So which should I use, or when should I use which? I'm a bit
            confused.
Sunday, 26 November 2017
Java - Method accessibility inside package-private class?
Answer
If I
have a java class which is package-private (declared with "class", not "public class"),
there is really no difference if the methods inside are declared public or protected or
package-private,
right?
Well maybe
            not immediately. But if you then (or in the future) declare a 'protected' or 'public'
            class that inherits from the package-private class, then the visibility of the members
            of the original class do
            matter.
As @kmccoy points out, declaring the
            class as final removes the possibility of subclasses.
            
But this is really only window-dressing. If you
            then decide that you really need to create subclasses, you simply remove the
            final ... and then you are back in the situation where the
            choice of access modifiers does
            matter.
IMO, the bottom line is that
            you should pick the most appropriate modifiers ... even if it is not necessary right
            now. If nothing else, your choice of modifiers should document your intent as to where
            the abstraction boundaries lie.
php - file_get_contents shows unexpected output while reading a file
I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...
- 
I would like to split a String by comma ',' and remove whitespace from the beginning and end of each split. For example, if I have ...
- 
I have an app which needs a login and a registration with SQLite. I have the database and a user can login and register. But i would like th...
- 
I have a method in repository with this implementation which returns a Task Task > GetAllAppsRequestAsync(); I write the getter which cal...
 
No comments:
Post a Comment