Create a function with a generic input in Java (different potential inputs with same function names)

I am quite new to Java and read about the generic inputs and classes. I was wondering if we can have a function for example named as getNewWeights(genericInput) where the genericInput can be different class types but they have similar functions, as follows:

public static Double getNewWeight(Class<T> genericInput) {
    double weight = 0.0;
    //logic
    weight = genericInput.getCalcuatedWeight(INPUTS); 
    //logic
    return weight
}

while genericInputs of any type has same getCalcuatedWeight function.

for example: if genericInput class type is Car or Train both of these classes have a public function as getCalcuatedWeight that returns a double value.



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation