Jump to content

Problem with providing the methods [java, gwt]

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
piotr286

piotr286

    Newbie

  • Members
  • Pip
  • 2 posts
Hi,

I'm using gwt framework called smartgwt (however, problem concerns gwt and java) There you can find HLayout class which can contain members. You can add them using:

addMember(Canvas component)

I created RectConainer class which extends HLayout class. Then, I created another class Rect which extends Canvas class indirectly. Right now, I want RectConainer to provide:

addMember(Rect component)

instead of:

addMember(Canvas component)

In other words, I want RectConainer to provide all inherited method + addMember(Rect component), but without addMember(Canvas component). The only way how to do it (which I know) is to use Composite class, but then I block all inherited methods. Because I've many of them then, I'd have to write many line of code to provide them again. So do you have any better ideas how to solve this problem?

Thanks in advance

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
Override the addMember(Canvas component) and throw an exception in there or don't do anything inside the overridden method.

Possible exceptions that would make sence: NoSuchMethodException or UnsupportedOperationException

This is the only possible way. Java uses the exception way itself when turning a Collection into an unmodifiable one.

List<Integer> list = new ArrayList<Integer>();

List unmodifiable = Collections.unmodifiableList(list);
The 'list' has all the methods like add, remove etc.
'unmodifiable' has all those methods too, but they throw errors:

Quote

Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableCollection.add(Collections.java:1018)