2

I am new to Java, coming from PHP. Here is a snippet of code:

public List<WSOrderInfo> getOrderInfoList() {

    List<WSOrderInfo> detailList = new ArrayList<WSOrderInfo>();

I am wondering the following: What is the term in the angle brackets? (<WSOrderInfo>) Is this defined as part of some scope of the class? Does it reference an external variable?

Thanks!

3
  • 2
    that's generics docs.oracle.com/javase/tutorial/java/generics Commented Dec 1, 2015 at 20:32
  • Correct, it is generics. It is specifying the type that the List will contain. For example, it could be string, MyCoolType, etc. Commented Dec 1, 2015 at 20:33
  • 1
    I understand no one knows everything but what happened with searching for an answer before shooting the question. Not necessarily related to this post, but I see so many questions on stackoverflow that it makes me think 'did you try to at least google this' if not go to Java Tutorial :( Commented Dec 1, 2015 at 22:05

1 Answer 1

2

As already mentioned in the comments these terms are specifying the type of objects your list contains. First, you should specify the concrete list, here ArrayList in your case. You may take a look at the List Interface to get familiar with.

You should also know that in Java generic type arguments must be objects and because primitives do not extend Object they can not be used. So use e.g. List<Integer> instead of List<int>, since the first one is the wrapper class of int. Just take a look at Wrapper Classes.

Hope this helps you to get more familiar with the topic.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.