codenameone / CodenameOne

Cross-platform framework for building truly native mobile apps with Java or Kotlin. Write Once Run Anywhere support for iOS, Android, Desktop & Web.
https://www.codenameone.com/
Other
1.71k stars 409 forks source link

Rewrite interface "com.codename1.ui.list.ListModel" to use generics #679

Closed codenameone closed 9 years ago

codenameone commented 9 years ago

Original issue 679 created by codenameone on 2013-04-27T14:10:46.000Z:

Hi,

I tried to implement the interface com.codename1.ui.list.ListModel a basic list class that can be reused in all of my lists.

I came across the limitation that you're using Object here all the way. What about using generics?

I rewrote the interface to work with generics and posted it in a gist together with a possible use-case: https://gist.github.com/SimonSimCity/5473222

Here's a gist for the same use-case and what I had to do when the model isn't changed: https://gist.github.com/SimonSimCity/5473110

Basically I have to do a lot more type-casts.

Bye Simon

codenameone commented 9 years ago

Comment #1 originally posted by codenameone on 2013-04-28T04:43:57.000Z:

The interfaces predated Java 5 support (or Codename One) by 4 or 5 years. This is way lower priority compared to changing all the usage of Vector/Hashtable to Collection/Map and using unsynchronized versions which would actually impact performance favorably (hugely important). However, we aren't doing that yet because incorporating Java 5 features would break RIM/J2ME build since our Java5 support is still not open sourced. We need to open source it in order to start on that road.

Rewriting this to work with generics would be problematic since developers build against a fixed interface and send the build (without Codename One) to the server, this might impact the compiled classes and break for people building against a slightly older version which will mean the migration to a new API will be painful. It doesn't mean we won't eventually do this but it explains why we aren't rushing towards this.

FYI you can easily work around this by using a proxy to generify the interface.

codenameone commented 9 years ago

Comment #2 originally posted by codenameone on 2013-04-28T07:31:26.000Z:

That said, you don't want to use generics in the code for the API, but I can use it in userland-code? Or should I also avoid it in my code?

codenameone commented 9 years ago

Comment #3 originally posted by codenameone on 2013-04-28T07:35:51.000Z:

Its OK in userland and we also added it to a few select classes (cloud classes) where Java 5 features were important. We will add it all around when we get the chance to open source some of the backend code that will allow people to compile it.

codenameone commented 9 years ago

Comment #4 originally posted by codenameone on 2013-08-20T15:48:33.000Z:

This is fixed now.