• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Making My Return Type

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?"
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When you create a class, that is creating a type. Then you can use it as a return type.
 
naval kumar
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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;
}

}
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic