fonz
March 17th, 2009, 17:37
I have an abstract Java class with one (non-abstract) static method, e.g. like so:
public abstract class Foo
{
public abstract void bar();
public static void feep()
{
// actual code here
}
}
So far, so good. This works. But now for the punchline: I would like to be able to have the function feep() able to throw an exception, but simply doing the following (changes highlighted) doesn't work:
public abstract class Foo
{
public abstract void bar();
public static void feep() throws SomeException
{
// actual code here
if(something)
throw new SomeException("whatever");
}
}
This results in a compiler error non-static variable this cannot be referenced from a static context with a mark at the beginning of new.
Anyone know how to fix this?
Thanks in advance,
Alphons
public abstract class Foo
{
public abstract void bar();
public static void feep()
{
// actual code here
}
}
So far, so good. This works. But now for the punchline: I would like to be able to have the function feep() able to throw an exception, but simply doing the following (changes highlighted) doesn't work:
public abstract class Foo
{
public abstract void bar();
public static void feep() throws SomeException
{
// actual code here
if(something)
throw new SomeException("whatever");
}
}
This results in a compiler error non-static variable this cannot be referenced from a static context with a mark at the beginning of new.
Anyone know how to fix this?
Thanks in advance,
Alphons