Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Java Protected access problem

  • 08-10-2005 1:27pm
    #1
    Registered Users, Registered Users 2 Posts: 1,322 ✭✭✭


    Im trying to use a protected attribute i seen in the URLConnection class but because its protected it wont compile for me.

    The attribute is the protected connected attribute that returns a boolean, true if the connection is made etc...

    How do i access this method as it would be really handy for the project.

    The actual compiler error is
    " connected has protected access in java.net.URLConnection"

    any help would be great.


Comments

  • Registered Users, Registered Users 2 Posts: 1,272 ✭✭✭i_am_dogboy


    Protected attributes and methods are only available to the class itself, classes in the same package of sub classes. I've never used URLConnection before so I don't know how it works, but I'm guessing the method is declared protected for a good reason, if you want access extend the URLConnection class.


  • Registered Users, Registered Users 2 Posts: 885 ✭✭✭clearz


    Extend the URLConnection class and in your new class create a public method that calls the protected method. Then use your new clanss wherever you are using the URLConnection class in your main code.

    And yes its probably protected for a good reason but thats how to get arround it anyway.


  • Registered Users, Registered Users 2 Posts: 1,322 ✭✭✭Mad_Max


    Thanks for the advice. I couldnt actually get that to work for some reason it wouldnt let me extend the URLConnection class..

    However i found another way of checking the connections by requesting the headers and then going from there....seems to work ok now.

    Thanks again for the help.


  • Closed Accounts Posts: 324 ✭✭madramor


    public class MyURLConnection extends URLConnection{
        
        public MyURLConnection(URL u){
            super(u);
        }
        public void connect() throws IOException{
        }
        public boolean isConnected(){
            return this.connected;
        }
    }
    


Advertisement