John Jai wrote:Have two constructors... Let one get Map<String,String> and the other Map<String,MyString>
albert kao wrote:It is harder than it looks - because of type erasure of the generic type, the two methods are considered the same
Paul Clapham wrote:
albert kao wrote:It is harder than it looks - because of type erasure of the generic type, the two methods are considered the same
What generic type? There isn't any such thing in your code.
albert kao wrote:MyString is a third party class which I don't have the source code. It has the toString() method.
...
MyComboBox should accept both Map<String, String> and Map<String, MyString> as parameters.
How to rewrite my program?
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Paul Clapham wrote:Or just work with Map<String, Object>.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Winston Gutkowski wrote:
albert kao wrote:MyString is a third party class which I don't have the source code. It has the toString() method.
...
MyComboBox should accept both Map<String, String> and Map<String, MyString> as parameters
Why? Does your ComboBox update the MyString?
...
Winston
No, ComboBox does not update the MyString.
Now I create MyComboBox2 so that both map1 & map2 are supported:
My goal is to rewrite MyComboBox so that both map1 & map2 are supported because MyComboBox occur in a lot of source codes already.
These are the current sample usage, which will cause casting exception.
Is it possible to rewrite MyComboBox so that the following code will work?
albert kao wrote:MyString does not implement CharSequence.
"Leadership is nature's way of removing morons from the productive flow" - Dogbert
Articles by Winston can be found here
Paul Clapham wrote:Then based on what I've seen there, your best choice is to convert your Map<String, MyString> objects to Map<String, String> objects. This would take about six lines of code, including the line which converts a MyString to a String via the toString() method.