I have the following method within a class that I do not understand its purpose:
private PageInfo getPage(){} (note that PageInfo is capitalized).
PageInfo is a class which makes this different as getters are typically used within methods in a class.
I can create a Class variable as: private PageInfo page; I can then create a getter for it as: public PageInfo getWebpage() {return webpage;}
However, this is unclear what is its purpose and why. I would greatly appreciate a response and thanks in advance!
private PageInfo getWebPage(URL url, URL parentUrl) throws IOException
{
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
int responseCode = connection.getResponseCode();
String contentType = connection.getContentType();
// Note: contentLength == -1 if NOT KNOWN (i.e. not returned from server)
int contentLength = connection.getContentLength();
PageInfo p = new PageInfo(url,parentUrl,contentType,contentLength,responseCode);
InputStreamReader rdr =
new InputStreamReader(connection.getInputStream());
p.extract(rdr);
rdr.close();
connection.disconnect();
return(p);
}
RESOLVED:
The above method has been written within a different class, and preceding the methods' name is the name of its class. the method's name doesn't comply to the naming convention (doesn't need to). Its method access modifier is void by default as no modifier has been declared, and as such it supposedly doesn't return anything however there is an acception to the rule. Accordingly it can return the initialization of its Class PageInfo. Otherwise, it can be set as return null (return: null;).
private MyClass getInfo() {
int e = 300;
int t = 10;
MyClass z = new MyClass(22);
return z; // z is the initialization of MyClass
// return null; is also valid
}
It sounds like you're expecting this method to be an accessor based on its naming convention.
Instead it looks like it's a private helper method for generating a PageInfo object from the provided urls(in fact it makes a call to a constructor that requires additional paramerers, which it derives from the provided parameters). Without seeing the larger context I can't tell you exactly what the purpose is, but it's certainly not doing the same thing you described with your private class variable and public accessor example.
Hopefully this helps - if not, I'd recommend clarifying your question, or providing additional code.
Edit: you flagged this with intellij-idea - if that's the IDE you're using, try highlighting the method name and pressing alt-f7 to find usages. This should provide you with some insights about where this method is being called and why.