After that, you should be able to call the method without cast not object(...).

Are you aware of the NiceSwing? project? This was done by Martin. It contains many retypings for java.awt, java.beans and javax.swing. It also has utility methods and classes, to do GUI stuff more easily, using Nice features like anonymous functions. At the moment, I think it is only available as a CVS module, but jars should be made at some point (a problem is that Martin is very busy at the moment). I just added some retypings for JOptionPane.

It would be interesting to see how that can help writing the GUI for flow4j. Also, related to the Eclipse plugin, a similar library could be done on top of SWT. -- DanielBonniot

How do you know that the last element has the right type? -- DanielBonniot

The draggable points of a Connection are Handles. The first and the last are connected to flowlets, thats why they are called ConnectionHandles, and the handles in between are EllbowHandles. There can be zero or more EllbowHandles?. I defined it like this. -- AlexGreif

Interesting. Here it is the logic of the system that guarantees the cast will not fail.
I think you could take into account this logic in the types. One possibility is to keep a reference to the handles on both extremities in fields of type ConnectionHandle.
If you wish, you can encapsulate the handles in a Handle class:

Interesting too. But IMO not very nice design, because the class Figure (the super class of all) has the member List<Handle> handles. And I want to store all handles in one List. A Connection has this speciality that it has two types of handles. Besides this I can iterate easily if all Handles are in one List. -- AlexGreif

OK. Then could you add in Connection the two fields, while keeping everything in the list? -- Daniel

Then the info is redundant, and I have to update both. Where do I profit if I introduce two fields? -- Alex

The type information is not redundant. A benefit is that you make sure that there is no cast, that might fail at runtime in some strange condition. On the other hand, it is true that you then need to guarantee that the value in the field is the same as in the list.
If you have a set method in the parent to build the list, then you could override it to set the fields when the index is 0 or length - 1, and the call super.

I agree that the benefit is discutable. An alternative is to use the cast.
In a future version of Nice, I could imagine that you could do:

Hand h = cast(handles.get(handles.size()-1));
assert h instanceof ConnectionHandle;
// Now you can use h as a ConnectionHandle.

You need notNull, because connectorListeners is not a local variable. This is explained in OptionTypes. A solution is there too.

What is the type of figure.getHandles() ?

java.util.List<Handle> getHandles() = handles;

ConnectorHandle, that extends Handle implements ConnectorListener

Interesting. So you have a value of type A, a List<B> with B extends A,
and you want to know if the value is in the list, right?
We were discussing with Arjan if this is ever needed.
The point is, it can only be true if the value is of type B.
But now I can believe this is really useful.

If it is really this, we will change the type of contains in nice.lang.
After that, you won't need this cast. -- DanielBonniot

Are you not sure it is safe, or if it is useful?
I checked the javadoc, it is true that you cannot add elements, so this must be safe. I'm not sure how useful it will be, but it does not harm to do it. Maybe it will turn out useful in some situations. And we can say that Nice allows this, while Java 1.5 cannot! :-) -- Daniel

It reminds me that I still should write something about retyping, at least the is no shortage of examples -- ArjanB

For those that are solved, if you feel that some documentation should be added (for the numeric types, I updated the User manual, so that it compares with the Java syntax). After that they can be deleted.

Some will probably need to stay, when they are a good example of a typing problem, and how to solve it. So we can keep those there.