java.util.List

26 views
Skip to first unread message

ben fenster

unread,
Nov 23, 2009, 6:29:10 AM11/23/09
to Google Web Toolkit
why cant i make a sub class for java.util.List
every time i do i get compile errors

Lothar Kimmeringer

unread,
Nov 23, 2009, 7:10:43 AM11/23/09
to google-we...@googlegroups.com
ben fenster schrieb:
> why cant i make a sub class for java.util.List
> every time i do i get compile errors

Reading the error-message should help but independent
from that, the the answer is: It's an interface, baby.


Regards, Lothar

ben fenster

unread,
Nov 23, 2009, 7:15:39 AM11/23/09
to Google Web Toolkit
i know !!!
but when i try to implement it and the compile it i get a general
error saying my main module cant be loaded
so baby ! show me any class you create that inherites from List and of
course compile it !

Lothar Kimmeringer

unread,
Nov 23, 2009, 7:49:44 AM11/23/09
to google-we...@googlegroups.com
ben fenster schrieb:
> i know !!!

So why do you try to create a subclass of an interface?

> but when i try to implement it

Implement != subclass.

> and the compile it i get a general
> error saying my main module cant be loaded

You try to compile it for deployment or are we talking about
the hosted mode? if the latter, what's the error-message
showing up in the details-pane if you click on the main-entry

> so baby ! show me any class you create that inherites from List and of
> course compile it !

I come to the impression that you think that I'm some kind
of support-guy you have the right to use for free. That's
not the case, so please work on your way of asking questions:

- Don't use exclamation and question marks excessively
- Give as much information as possible to be able to
reproduce or at least understand your problem
- Don't forget: It's you, who want to be helped, so ask
in a way motivating as much people as possible to
help you.

I never needed to create a new implementation of java.util.List
but alway use ArrayList for the client side of the application.
Most likely java.util.List is not part of the client JRE that
is converted to Javascript leading to the error (but that's just
a guess, the error-message in the details-pane should clearify
that).


Regards, Lothar

ben fenster

unread,
Nov 23, 2009, 8:16:19 AM11/23/09
to Google Web Toolkit
i dont think anyone is working for me i just found what seems to be a
very big bug in gwt since for some reason its not possible to
implement the list interface and i belive it is a potential problem
for alot of people other then me

import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class SmartQueue<T> implements List<T>{

protected ArrayList<T> m_items;
protected int m_Limit=-1;
/**
* constructor
* @param lim = limit of queue to set
*/
public SmartQueue()
{

}
public SmartQueue(int lim)
{
m_Limit=lim;
}

/**
* Enqueue a member into head of queue
* @param val-val to insert
*/
public T Enqueue(T val)
{
m_items.add(0, val);
return (m_Limit>0 && m_items.size()>m_Limit) ? Dequeue() : null;
}
/**
* Enqueue a member into a chosen pos at the queue
* @param val-val to insert
*/
public T Enqueue(T val,int at)
{
m_items.add(at, val);
return (m_Limit>0 && m_items.size()>m_Limit) ? Dequeue() : null;
}

/**
* Enqueue a member into head of queue
* @param val-val to insert
*/
public Collection<T> Enqueue(Collection<? extends T> coll)
{
m_items.addAll(0, coll);
if(m_Limit>0 && m_items.size()>m_Limit)
{
return Dequeue(m_items.size() - m_Limit);
}
return null;
}
/**
* Enqueue a member into head of queue
* @param val-val to insert
*/
public Collection<T> Enqueue(Collection<? extends T> coll,int at)
{
m_items.addAll(at, coll);
if(m_Limit>0 && m_items.size()>m_Limit)
{
return Dequeue(m_items.size() - m_Limit);
}
return null;
}


/**
* Dequeue a member from tail end of queue
* @return T - the member of the queue that was removed
*/
public T Dequeue()
{
int end = m_items.size()-1;
T res = m_items.get(end);
m_items.remove(end);
return res;
}
/**
* Dequeue a member list from tail end of queue
* @return T - the member of the queue that was removed
*/
public Collection<T> Dequeue(int count)
{
Collection<T>res = new ArrayList<T>();
for (int i = m_items.size()-count; i < m_items.size(); i++) {
res.add(get(i));
m_items.remove(i);
}
return res;
}

/**
* get the maximum capacity of the queue
* @return maximum capacity of the queue
*/
public int GetLimit()
{
return m_Limit;
}
/**
* sets maximum capacity of the queue
* @param lim-the limit of the queue to set
*/
public void SetLimit(int lim)
{
m_Limit=lim;
}

public void SetItemPosition(int from,int to)
{
if(from >0 && from < m_items.size()&& to >0 && to < m_items.size())
{
Collections.swap(m_items, from, to);
}
}
private Collection<T> GetAndRemoveOverLimit()
{
if(m_Limit>0 && m_items.size()>m_Limit)
{
return Dequeue(m_items.size() - m_Limit);
}
return null;
}
private void RemoveOverLimit()
{
if(m_Limit>0 && m_items.size()>m_Limit)
{
Dequeue(m_items.size() - m_Limit);
}
}
@Override
public boolean add(T e) {
boolean res = m_items.add(e);
RemoveOverLimit();
return res;
}
@Override
public void add(int index, T element) {
RemoveOverLimit();
m_items.add(index,element);
}
@Override
public boolean addAll(Collection<? extends T> c) {
boolean res =addAll(c);
RemoveOverLimit();
return res;
}
@Override
public boolean addAll(int index, Collection<? extends T> c) {
boolean res =addAll(index,c);
RemoveOverLimit();
return res;
}
@Override
public void clear() {
m_items.clear();

}
@Override
public boolean contains(Object o) {

return m_items.contains(o);
}
@Override
public boolean containsAll(Collection<?> c) {
// TODO Auto-generated method stub
return m_items.containsAll(c);
}
@Override
public T get(int index) {
// TODO Auto-generated method stub
return m_items.get(index);
}
@Override
public int indexOf(Object o) {
// TODO Auto-generated method stub
return m_items.indexOf(o);
}
@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return m_items.isEmpty();
}
@Override
public Iterator<T> iterator() {

return m_items.iterator();
}
@Override
public int lastIndexOf(Object o) {

return m_items.lastIndexOf(o);
}
@Override
public ListIterator<T> listIterator() {
// TODO Auto-generated method stub
return m_items.listIterator();
}
@Override
public ListIterator<T> listIterator(int index) {
// TODO Auto-generated method stub
return m_items.listIterator(index);
}
@Override
public boolean remove(Object o) {
return m_items.remove(o);
}
@Override
public T remove(int index) {
// TODO Auto-generated method stub
return m_items.get(index);
}
@Override
public boolean removeAll(Collection<?> c) {
// TODO Auto-generated method stub
return m_items.removeAll(c);
}
@Override
public boolean retainAll(Collection<?> c) {
// TODO Auto-generated method stub
return m_items.retainAll(c);
}
@Override
public T set(int index, T element) {
// TODO Auto-generated method stub
return m_items.set(index, element);
}
@Override
public int size() {
// TODO Auto-generated method stub
return m_items.size();
}
@Override
public List<T> subList(int fromIndex, int toIndex) {

return m_items.subList(fromIndex, toIndex);
}
@Override
public Object[] toArray() {
return m_items.toArray();
}
@Override
public <T> T[] toArray(T[] a) {
// TODO Auto-generated method stub
return m_items.toArray(a);

ben fenster

unread,
Nov 23, 2009, 8:17:49 AM11/23/09
to Google Web Toolkit
by the way the error is
[ERROR] Failure to load module 'vzooo'

On 23 נובמבר, 14:49, Lothar Kimmeringer <j...@kimmeringer.de> wrote:

Paul MERLIN

unread,
Nov 23, 2009, 8:50:47 AM11/23/09
to google-we...@googlegroups.com
Le lundi 23 novembre 2009 12:29:10, ben fenster a écrit :
> why cant i make a sub class for java.util.List
> every time i do i get compile errors

Documentation is clear :

"Google Web Toolkit includes a library that emulates a subset of the Java runtime library. The list
below shows the set of JRE packages, types and methods that GWT can translate automatically.
Note that in some cases, only a subset of methods is supported for a given type."

http://code.google.com/intl/fr/webtoolkit/doc/1.6/RefJreEmulation.html

java.util.List is in the emulated list but you'd better check if all methods are supported

I tried to write an empty implementation (no time to waste) of List<String>, and GWTCompiler seems to be happy with it,
so I'd suspect an error in your code (using something else that is not supported by gwt jre emulation).

By the way, you're asking insistingly without giving any valuable information for us to help you ... IMHO that's
impolite.

/Paul

Nathan Wells

unread,
Nov 23, 2009, 8:53:21 AM11/23/09
to Google Web Toolkit
1) Is your class in a "client" package? by that, I mean does the
parent package have a *.gwt.xml file, and does it declare the
SmartQueue package as a source package?

If you haven't already, you might want to read this:

http://code.google.com/webtoolkit/doc/1.6/DevGuideCodingBasics.html

along with the rest of the Developer Guide. and probably the FAQ...
and the Reference Guide... and watch a few Google I/O videos.

ben fenster

unread,
Nov 23, 2009, 9:02:14 AM11/23/09
to Google Web Toolkit
yes its in a client package and i also tried to create an empty
implementation of INTEGER and it didnt work
did you try to run the module with the empty List<String> in hosted
mode

ben fenster

unread,
Nov 23, 2009, 9:05:18 AM11/23/09
to Google Web Toolkit
im sorry but i was under some presure i have a close deadline and
thats pretty much the only problem idid you create an anonymous class
or a class that implements the list

Paul MERLIN

unread,
Nov 23, 2009, 9:06:06 AM11/23/09
to google-we...@googlegroups.com
Le lundi 23 novembre 2009 15:02:14, ben fenster a écrit :
> did you try to run the module with the empty List<String> in hosted
> mode
Nope.
Did you try to get a more valuable error message ?

/Paul

Paul MERLIN

unread,
Nov 23, 2009, 9:07:41 AM11/23/09
to google-we...@googlegroups.com
Le lundi 23 novembre 2009 15:05:18, ben fenster a écrit :
> im sorry but i was under some presure i have a close deadline and
> thats pretty much the only problem idid you create an anonymous class
> or a class that implements the list

public class Test implements List<String> { ... }

ben fenster

unread,
Nov 23, 2009, 9:44:20 AM11/23/09
to Google Web Toolkit

import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class bla implements List<String> {

@Override
public boolean add(String e) {
// TODO Auto-generated method stub
return false;
}

@Override
public void add(int index, String element) {
// TODO Auto-generated method stub

}

@Override
public boolean addAll(Collection<? extends String> c) {
// TODO Auto-generated method stub
return false;
}

@Override
public boolean addAll(int index, Collection<? extends String> c) {
// TODO Auto-generated method stub
return false;
}

@Override
public void clear() {
// TODO Auto-generated method stub

}

@Override
public boolean contains(Object o) {
// TODO Auto-generated method stub
return false;
}

@Override
public boolean containsAll(Collection<?> c) {
// TODO Auto-generated method stub
return false;
}

@Override
public String get(int index) {
// TODO Auto-generated method stub
return null;
}

@Override
public int indexOf(Object o) {
// TODO Auto-generated method stub
return 0;
}

@Override
public boolean isEmpty() {
// TODO Auto-generated method stub
return false;
}

@Override
public Iterator<String> iterator() {
// TODO Auto-generated method stub
return null;
}

@Override
public int lastIndexOf(Object o) {
// TODO Auto-generated method stub
return 0;
}

@Override
public ListIterator<String> listIterator() {
// TODO Auto-generated method stub
return null;
}

@Override
public ListIterator<String> listIterator(int index) {
// TODO Auto-generated method stub
return null;
}

@Override
public boolean remove(Object o) {
// TODO Auto-generated method stub
return false;
}

@Override
public String remove(int index) {
// TODO Auto-generated method stub
return null;
}

@Override
public boolean removeAll(Collection<?> c) {
// TODO Auto-generated method stub
return false;
}

@Override
public boolean retainAll(Collection<?> c) {
// TODO Auto-generated method stub
return false;
}

@Override
public String set(int index, String element) {
// TODO Auto-generated method stub
return null;
}

@Override
public int size() {
// TODO Auto-generated method stub
return 0;
}

@Override
public List<String> subList(int fromIndex, int toIndex) {

return null;
}

@Override
public Object[] toArray() {
// TODO Auto-generated method stub
return null;
}

@Override
public <T> T[] toArray(T[] a) {
// TODO Auto-generated method stub
return null;
}

}


i am did the exact same thing and got

[ERROR] Line 131: The method subList(int, int) of type bla must
override or implement a supertype method

Jason Morris

unread,
Nov 23, 2009, 9:52:14 AM11/23/09
to google-we...@googlegroups.com
Hi ben,

If you are using a version of GWT < 2.0 this error appears because the standard GWT List interface
doesn't have the subList method. You can either remove the @Override annotation from that method, or
extend AbstractList instead of implementing List directly (generally considered a better option
anyways).

You could also upgrade to GWT 2.0-rc, which has the subList method included in the interface definition.

Hope that helps.
//Jason
> --
>
> You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
> To post to this group, send email to google-we...@googlegroups.com.
> To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=.
>
>
>

ben fenster

unread,
Nov 23, 2009, 10:02:24 AM11/23/09
to Google Web Toolkit
no i am using gwt 1.7
i cant understand the error because i do implement the method
moreover the method was auto filled by eclipse

ben fenster

unread,
Nov 23, 2009, 10:11:32 AM11/23/09
to Google Web Toolkit
thanks i removed the override and it worked can you please tell me why
did act like that since the eclipse filled out the implementation
acording to the interface and if the method is not suppored how did
it got into the imlementation in the first place

On 23 נובמבר, 16:52, Jason Morris <lem...@gmail.com> wrote:

ben fenster

unread,
Nov 23, 2009, 11:25:51 AM11/23/09
to Google Web Toolkit
thanks i removed the override and it worked can you please tell me why
did act like that since the eclipse filled out the implementation
acording to the interface and if the method is not suppored how did
it got into the imlementation in the first place

On 23 נובמבר, 16:52, Jason Morris <lem...@gmail.com> wrote:

Jason Morris

unread,
Nov 24, 2009, 12:43:49 AM11/24/09
to google-we...@googlegroups.com
Eclipse fills in methods based on the JDK installed, not the GWT emulated JRE. GWT's implementation
of the JRE sits in the package com.google.gwt.emul.java, not java.

ben fenster

unread,
Nov 24, 2009, 3:32:13 AM11/24/09
to Google Web Toolkit
10x u saved me :)
Reply all
Reply to author
Forward
0 new messages