File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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: 30353
    
150

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: 38436
    
  23
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: 38436
    
  23
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.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Making My Return Type