Skip to Main Content

Overridable method params in Java

User_WZNFNAug 15 2022 — edited Aug 15 2022

In 2012 (10 years ago, 317 large tasks ago in my ToDo list…) I asked a question here:
How this is called and why it is not allowed? (0 Bytes)
I was trying to create a rigid body mockup in Java.
Rigid body is whereas you pull a leg and the rest of the body reacts, according to the body part that has been moved — which is the body part that moves the body part that is connected to it. So if you pull leg, leg pulls body body pulls hand and hand pulls finger. Personally, very recommended.

If you’re familiar with some GUI framework, got some idea about MVC and know an OO programming language, this task should be a piece of cake.

But it isn’t.
When you start up the code you begin with some mockup like this:

BodyPart {
abstract public void followBodyPart(BodyPart part);

public class Head extends BodyPart{
public void followBodyPart(Body body ) { //1.Will NOT work
public class Body extends BodyPart{
public void followBodyPart(Head head ) {
public void followBodyPart(Forearm leftForearm ) {
//Arm, Forearm, etc...

But since we cannot override a method param, we’d end up with Class type checks 34 times for 17 body two way connected body parts!
This way of coding with a 30yo language is mal. Mui mal.

So what I suggest is to implement in Java a new feature:
Overridable method parameter

… method(overridable GenericCar car)

That way, once a class that overrides the above Interface or Class will override the method “method”, *it will be able to override the method parameter type of GenericCar car,* knowing, say, from some annotation that “method” instantiates ConcreteCarA which accepts only ConcreteCarC.
I think such thing could make Java beautiful.

What do you think? Would you raise it (with me) to RFC (Request For Comments)?

I think it could be a good Standard in today’s programming languages, in my opinion it’s beautiful and open the door for coding to non professional programmers such as kids and teachers. Also it allows bringing up new ideas into SW from non SW people. And also opens the door for new SW paradigms, such as new way of thinking - I think the next generations will seize it 1000% in an exponential way and will create totally new SW architectures with this flexible “overridable method param” thing.

So, thoughts?
Many thanks,

Post Details
Added on Aug 15 2022