This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Making My Return Type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Making My Return Type" Watch "Making My Return Type" New topic
Author

Making My Return Type

naval kumar
Ranch Hand

Joined: Jul 08, 2012
Posts: 37
Dear Sir,
I want to know that, how can i define my return type?
like
public Myreturntype fun1()
{
return Myvalue;
}
As i have already used predefined Return type like String,int But I want to know How can We make My return type?"
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30068
    
149

When you create a class, that is creating a type. Then you can use it as a return type.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
naval kumar
Ranch Hand

Joined: Jul 08, 2012
Posts: 37
Actually, i was Confused with the Iterator Method in Arraylist like "Iterator itr = ArrayList.iterator();" In The ArrayList It has one of method "public Iterator iterator()" . But i m not getting How the Arraylist implements This iterator() function Because the Iterator is a interface and has only three methods boolean hasNext(), Object next() ,void remove().

As i am thinking In the Arraylist Its written like that Or something else??

public class Arraylist extends AbstarctList implements List, RandomAccess, Cloneable
{
public Iterator iterator()
{
Iterator it=new Arraylist ();
return it;
}

}
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37926
    
  22
That is how I would do it, with an anonymous class. To find out more, unzip the file called src.zip which is in your Java installation directory and explore that. If I remember correctly, that ListIterator<T> interface extends Iterator.
naval kumar
Ranch Hand

Joined: Jul 08, 2012
Posts: 37
please Clear me one more things that if i am doing like it "HashSet s = new HashSet();" instead of "Set s = new HashSet();".
Is there Any problem?? Or Any Suggestion you can give me as A programming concept?

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37926
    
  22
It is best to use
Set<Foo> mySet = new HashSet<Foo>();
…because you can change the implementation of the set to a TreeSet very simply.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Making My Return Type
 
Similar Threads
How to write JUnit for Void method
Will this cause auto-failure?
Generic Question
query
Calling Bean Code From JSP