This discussion is archived
1 Reply Latest reply: Aug 31, 2012 3:14 AM by tschodt RSS

Capture conversion / generics boxing unboxing

Mohan Newbie
Currently Being Moderated
I don't have code examples because I am trying to understand this.

I have read pg. 91 in the JLS and want to know if there are any other code examples of capture conversion. Moreover I want to look at how boxing and unboxing work in the case of parameterized types. If there more complex examples it will help.

Hope this question is not too generic !

Thanks.
  • 1. Re: Capture conversion / generics boxing unboxing
    tschodt Pro
    Currently Being Moderated
    Mohan wrote:
    I don't have code examples because I am trying to understand this.

    I have read pg. 91 in the JLS
    Page 91 will differ from JLS version to JLS version.
    Please give the dotted location, like
    5.1.10 Capture Conversion
    Mohan wrote:and want to know if there are any other code examples of capture conversion.
    "other code examples"
    so you found
    public static void reverse(List<?> list) { rev(list); }
    private static <T> void rev(List<T> list) {
        List<T> tmp = new ArrayList<T>(list);
        for (int i = 0; i < list.size(); i++) {
            list.set(i, tmp.get(list.size() - i - 1));
        }
    } 
    and you did not think it relevant to quote it in your post
    so others can see what you have already found yourself
    and maybe make educated guesses what kind of different samples you might be looking for.
    Moreover I want to look at how boxing and unboxing work in the case of parameterized types. If there more complex examples it will help.
    I do not see anything you could not determine yourself by writing and running some small code samples.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points