2

I was using Java 1.7 for my Libgdx application, however i found i was getting a lot of "@Override" errors. So after searchin around online, i found out i should run with Java 1.6 compatibility to prevent this error. After going to window->preferences->java->compiler and changing the compatibility to 1.6, i find that i'm still receiving the @Override errors (The method ... must override a superclass method).

Any idea why this would still be happening? Do i really need to specify "@Override" for a function to override and carry out as scheduled by the Interface/Masterclass??

Here's the code if that helps:

package cowdawg.libgdx.namespace;

import java.io.IOException;
import java.io.InputStream;

import javax.microedition.khronos.opengles.GL10;

import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.files.*;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.ApplicationListener;
import com.badlogic.gdx.graphics.GL11;
import com.badlogic.gdx.graphics.Mesh;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.Texture.TextureFilter;
import com.badlogic.gdx.graphics.Texture.TextureWrap;
import com.badlogic.gdx.graphics.g3d.loaders.obj.ObjLoader;

public class LifeCycle implements ApplicationListener {

    String head;
    Mesh model;
    private PerspectiveCamera camera;

    @Override
    public void create() {
        //super.onCreate(savedInstanceState);
        //setContentView(R.layout.main);

        InputStream stream = null;
        try 
        {
            stream = Gdx.files.internal("Head/Head.obj").read();
            model = ObjLoader.loadObj(stream,true);
            stream.close();
        } 
        catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        Gdx.gl.glEnable(GL10.GL_DEPTH_TEST);
        Gdx.gl10.glTranslatef(0.0f, 0.0f, -3.0f);

        //Mesh m;
        //InputStream in = Gdx.files.internal("data/cube.obj").read();
        //m = ObjLoader.loadObj(in);
        //m.render(GL10.GL_TRIANGLES);
    }

    @Override
    public void dispose(){
    }

    @Override
    public void pause(){
    }

    protected int lastTouchX;
    protected int lastTouchY;
    protected float rotateZ = 0.01f;
    protected float increment = 0.01f;

    @Override
    public void render()
    {
        Gdx.gl.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
        Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
        camera.update();
        camera.apply(Gdx.gl10);
        Gdx.gl10.glTranslatef(0.0f, 0.0f, -3.0f);
        Gdx.gl10.glRotatef(rotateZ, rotateZ, 5.0f, rotateZ);
        model.render(GL10.GL_TRIANGLES);

        if (Gdx.input.justTouched())
        {
        }
        else if (Gdx.input.isTouched())
        {
        }
        rotateZ += increment;
        System.out.println(""+rotateZ);
    }

    @Override
    public void resize()
    {

    }

    @Override
    public void resume()
    {

    }

    @Override
    public void resize(int arg0, int arg1) {
        // TODO Auto-generated method stub

    }
}
Ice Phoenix
  • 1,001
  • 3
  • 16
  • 34
  • Curious to see the answer here. I haven't read about the Java language the way I have about .Net languages, but I had a coworker who always said "all functions in Java are virtual". This would tell me that @Override is redundant, right? – Rich Jan 24 '12 at 15:35
  • @Override is not neccessary, it is merely there for convenience, so if it gives you problems you can remove it. Nevertheless, it would of course be best if you found what causes the problem and fixed it. – Jave Jan 24 '12 at 15:38

2 Answers2

3

@Override annotation is just a safety mechanism. It is just a hint for the compiler the method is intended to override a parent method. If the method is not an override of a parent method compiler error is triggered.

Using it is optional, but could be useful for detecting method name/parameter typos.

dmaxi
  • 3,267
  • 1
  • 18
  • 15
2

Do i really need to specify "@Override" for a function to override

No it is optional and it should generate a warning.

On the other side, Androids API forces you (and generates a runtime error) to call the super for certain methods. see here Android Activity which overridden functions must call super.*

Community
  • 1
  • 1
PeterMmm
  • 24,152
  • 13
  • 73
  • 111