Method which the return-type is the same autoclass?

72 Views Asked by At

I have a doubt. Be the following Java Class code:

public class myClass{
    public myClass myMethod(){
        ...
    }
    ...
}

1) How could myMethod return type be the auto-class? It is no logican sense for me. 2) What does it mean?

Thanks :)

2

There are 2 best solutions below

0
On

There seems to be some spelling mistakes in questions, Seems like you are asking how can it is possible that method return type is same as class.

The Answer is: this is because Return type is just used for specifying datatype and class is Data type like Integer String.

This is example of factory design pattern



moving back to your question, myMethod return myClass means it return an Object of myClass
We can perform any operation on return value which you can perform on myClass object

0
On

Well, taking a look at your responses, guys, I consider my question should be not clear.

I don't have problemns in understand return type. It is perfectly natural return a class.

My doubt (not just one doubt in the life, but one doubt among many other) consists on the method return the same class in which this method is implemented. It looks like some kind of "loop", or "recursivity". I imagine a method returning a class IF this class is outside this method, because in this case the external class will be fully implemented. When a method return the same class in which this method is declared, in my thought the class is not fully implemented yet.

That was my doubt but I think today it is more clear to me.

Thanks to all responses.