Hi
I bumped into this problem this morning (I’ve already found a work around) but I’m curious to why my code is not working as I wanted
public class classA
//(1)
public void function(GL10 gl){
function(gl,useGLUtilsBool, useMipMapBool);
}
//(2)
public void function(GL10 gl,boolean useGLUtils, boolean
useMipMap){
generateTexture(gl, useGLUtils, useMipMap);
}
}
@Override
public class classB extends
classA{
//(3)
public void function(GL10 gl, boolean useGLUtils, boolean
useMipMap) {
function(gl);
}
//(4)
@Override
public void function(GL10 gl) {
super.function(gl);
}
Normally it should do (3)->(4)->(1)->(2)
but instead I get (3)->(4)->(1)->(3)->(4)->(1)…
what I don’t get is why classA function(…) (1) would call (3) and not (2)
Because of inheritance and polymorphism. You have overridden (mark this with
@Override) thefunction(GL10 gl, boolean useGLUtils, boolean useMipMap)method in the subclass, so each time this method is called on an instance of classB, the overriding method will be invoked, instead of the one in the superclass