Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to make the code compile and preserve functionality?

i am new into java.. How do i fix this, so it will compile and preserve the functionality without changing dingo method. So this code should check if Pingo is a valid class.

class Pingo<T> {
    public void dingo(T t ) {
        System.out.println(t.bingoString( )) ;
    }
}

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

The T is a generic type. In your case it’s the Object class which doesn’t have a method called bingoString. You need to create a class which has this method for the template. E.g.:

// still your class
class Pingo<T extends Blub> {
    public void dingo(T t) {
        System.out.println(t.bingoString());
    }
}
// a class which provides the signature
class Blub {
    public String bingoString() {
        return "test";
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading