Skip to content

Instantly share code, notes, and snippets.

@archie
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save archie/9784771 to your computer and use it in GitHub Desktop.

Select an option

Save archie/9784771 to your computer and use it in GitHub Desktop.

Revisions

  1. archie revised this gist Mar 26, 2014. 1 changed file with 0 additions and 18 deletions.
    18 changes: 0 additions & 18 deletions Viewer.java
    Original file line number Diff line number Diff line change
    @@ -25,22 +25,4 @@ public void process4(List<? extends Item> items) {
    for (Item i : items)
    i.process();
    }

    public static void main(String[] args) {
    Viewer viewer = new Viewer();
    viewer.process3(new ArrayList<TwitterItem>(Arrays.asList(new TwitterItem() {

    @Override
    public void process() {
    // some computation
    }

    @Override
    public String toString() {
    return "twitteritem";
    }

    })));
    }

    }
  2. archie revised this gist Mar 26, 2014. 1 changed file with 0 additions and 16 deletions.
    16 changes: 0 additions & 16 deletions Bytecode
    Original file line number Diff line number Diff line change
    @@ -1,16 +0,0 @@
    public void process3(java.util.List<?>);
    Code:
    0: aload_1
    1: invokeinterface #2, 1 // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
    6: astore_2
    7: aload_2
    8: invokeinterface #3, 1 // InterfaceMethod java/util/Iterator.hasNext:()Z
    13: ifeq 31
    16: aload_2
    17: invokeinterface #4, 1 // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
    22: astore_3
    23: aload_3
    24: invokevirtual #5 // Method java/lang/Object.toString:()Ljava/lang/String;
    27: pop
    28: goto 7
    31: return
  3. archie revised this gist Mar 26, 2014. 1 changed file with 16 additions and 0 deletions.
    16 changes: 16 additions & 0 deletions Bytecode
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    public void process3(java.util.List<?>);
    Code:
    0: aload_1
    1: invokeinterface #2, 1 // InterfaceMethod java/util/List.iterator:()Ljava/util/Iterator;
    6: astore_2
    7: aload_2
    8: invokeinterface #3, 1 // InterfaceMethod java/util/Iterator.hasNext:()Z
    13: ifeq 31
    16: aload_2
    17: invokeinterface #4, 1 // InterfaceMethod java/util/Iterator.next:()Ljava/lang/Object;
    22: astore_3
    23: aload_3
    24: invokevirtual #5 // Method java/lang/Object.toString:()Ljava/lang/String;
    27: pop
    28: goto 7
    31: return
  4. archie revised this gist Mar 26, 2014. 3 changed files with 8 additions and 20 deletions.
    7 changes: 0 additions & 7 deletions Item.java
    Original file line number Diff line number Diff line change
    @@ -1,7 +0,0 @@
    package wild;

    public interface Item {

    void process();

    }
    5 changes: 0 additions & 5 deletions TwitterItem.java
    Original file line number Diff line number Diff line change
    @@ -1,5 +0,0 @@
    package wild;

    public interface TwitterItem extends Item {

    }
    16 changes: 8 additions & 8 deletions Viewer.java
    Original file line number Diff line number Diff line change
    @@ -6,22 +6,22 @@

    public class Viewer {

    public void process(List<Object> items) {
    public void process1(List<Object> items) {
    for (Object i : items)
    i.toString();
    }

    public void process2(List<?> items) {
    for (Object i : items)
    i.toString();
    }

    public void process3(List<? extends Item> items) {
    public void process2(List<Item> items) {
    for (Item i : items)
    i.process();
    }

    public void process4(List<Item> items) {
    public void process3(List<?> items) {
    for (Object i : items)
    i.toString();
    }

    public void process4(List<? extends Item> items) {
    for (Item i : items)
    i.process();
    }
  5. archie created this gist Mar 26, 2014.
    7 changes: 7 additions & 0 deletions Item.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    package wild;

    public interface Item {

    void process();

    }
    5 changes: 5 additions & 0 deletions TwitterItem.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    package wild;

    public interface TwitterItem extends Item {

    }
    46 changes: 46 additions & 0 deletions Viewer.java
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,46 @@
    package wild;

    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;

    public class Viewer {

    public void process(List<Object> items) {
    for (Object i : items)
    i.toString();
    }

    public void process2(List<?> items) {
    for (Object i : items)
    i.toString();
    }

    public void process3(List<? extends Item> items) {
    for (Item i : items)
    i.process();
    }

    public void process4(List<Item> items) {
    for (Item i : items)
    i.process();
    }

    public static void main(String[] args) {
    Viewer viewer = new Viewer();
    viewer.process3(new ArrayList<TwitterItem>(Arrays.asList(new TwitterItem() {

    @Override
    public void process() {
    // some computation
    }

    @Override
    public String toString() {
    return "twitteritem";
    }

    })));
    }

    }