Inheriting a Singleton

Hi, I am having some trouble inheriting from a Singleton class.

I have a parent singleton class that looks like:

public class ProviewReportQueryWin{

private static ProviewReportQueryWin proviewReportQueryWin = null;

...

protected ProviewReportQueryWin(final ProviewReportGUI gui){

...

}

public static ProviewReportQueryWin getInstance(final ProviewReportGUI gui){

if(proviewReportQueryWin == null)

proviewReportQueryWin = new ProviewReportQueryWin(gui);

return proviewReportQueryWin;

}

...

}

and a subclass that extends ProviewReportQueryWin:

public class FailureReportQueryWin extends ProviewReportQueryWin {

private static FailureReportQueryWin failureReportQueryWin = null;

public FailureReportQueryWin(final ProviewReportGUI gui){

super(gui);

...

}

public static FailureReportQueryWin getInstance(final ProviewReportGUI gui){

if(failureReportQueryWin == null)

failureReportQueryWin = new FailureReportQueryWin(gui);

return failureReportQueryWin;

}

}

...

}

However, when I compile it I get an error for FailureReportQueryWin.getInstance(), saying that "The return type is incompatiable with ProviewReportQueryWin.getInstance(ProviewReportGUI)." Does anyone know where my problem is? Thanx!

[1380 byte] By [eugenelin89a] at [2007-9-28 20:00:23]
# 1

You are not allowed to overwrite a method with a method which only differs in the return type.

Having to static methods in a class hirachy with the same name is cause of confusion anyway. I'd therefore recommend to use names that include the returntype like

getProviewInstance

and

get FailureInstance

Note: that with static methods the method calls interpreted at compiletime anyway

regards

Spieler

spielera at 2007-7-12 18:51:08 > top of Java-index,Other Topics,Patterns & OO Design...
# 2
Thanx, that helps~ = )
eugenelin89a at 2007-7-12 18:51:08 > top of Java-index,Other Topics,Patterns & OO Design...