문제

How to rewrite the following 1.5+ constructs to 1.4?

final class FooList<T> extends AbstractList<T> implements ...
{
    private T[] tab;
    ...
}

public ListIterator<T> listIterator() {...}

public int bar(int x, Collection<? extends T> c) {...}

for (Foo f : s.baz(x)) {...}

for (Map.Entry<Object, Object> e : p.entrySet()) {...}  
도움이 되었습니까?

해결책

final class FooList extends AbstractList implements ...
{
    private Object[] tab;
    ...
}

public ListIterator listIterator() {...}

public int bar(int x, Collection c) {...}

for (Iterator it = s.baz(x).iterator(); it.hasNext();) {
  final Foo f = (Foo) it.next();
  ...
}

for (Iterator it = p.entrySet().iterator(); it.hasNext();) {
  final Map.Entry e = (Map.Entry) it.next();
  ...
}

Plus all the necessary downcasts, of course.

다른 팁

There are few thing not supported in Java 1.4 in your code

  1. Remove form your code.
  2. Use Object instead of your T reference.
  3. Change for loop to old index based.

You could try Retroweaver, it allows to use some features of Java 5 in Java 1.4.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top