Skip to Main Content

Java User Groups


For appeals, questions and feedback, please email

Static abstract methods in Java?

User_YNHC8Jun 11 2022

Now that c# finally allows the "static abstract" pattern to force subclasses to have a particular static method I was wondering if this could bw inspiring for the java dev team to do the same like they often did in the past. Of course the critical need for "static abstract methods" in c# for example in operators is not as huge in java. But face it. At some point or another we all wrote "static abstract" while prototyping a class hierarchy and sadly remembered that it can't be done. Another stone in the way of "static abstract" in java is type erasure. An great use for "static abstract" would be in a method like this: <p>
public static void <T extends Bar> foo() {; //<- static abstract method in Bar
But of course as I said type erasure prevents us to specialize T at runtime. But I heard that as part of a big type rework including things like C# struct like types the generics system is being reworked. I hope they add the "static abstract" patterns as part of this update.

Post Details
Added on Jun 11 2022