1

Hey stackoverflow community!

Kind of a newcomer to coding, so please go easy on me.

Basically I'm trying to get this code to return the owner when I call the getOwner method. All of this is in java!

Here's my code:

public class SmartCard<__name__> {
    public __name__ owner;
    public __name__ getOwner(){
        return owner;
    }
}

Am I approaching this the wrong way? Thanks for the help :)

Tom
  • 17,103
  • 8
  • 67
  • 75
Argentum
  • 57
  • 7

1 Answers1

5

I'm going to guess that the reason it's not getting returned means that getOwner returns null. That's because you haven't initialized owner to anything. This might be how you can do that:

public class SmartCard<__name__> {
    public __name__ owner = new __name__();
    public __name__ getOwner(){
        return owner;
    }
}

I say "might" because I don't know what __name__ is or how it can be initialized. This would be a good opportunity to learn about nulls and null pointer exceptions.

BTW, you should be aware that __name__ doesn't follow the java style guidelines.

Community
  • 1
  • 1
Daniel Kaplan
  • 62,768
  • 50
  • 234
  • 356