Thank you, you are right. I haven't thought this through when creating the TreeSet (and TreeMap, and soon TreeMultimap) API. Obviously, you have not understood how it works GWT, consider that GWT in compilation time, converts JAVA code into javascript ( but can not doing it for any class in the world ). Into the Main.gwt.xml there are set the packages what are included into the GWT compilation scope. Reading and modifying the text from the text file in Java. I wrote a quick method for you that I think does what you want, i.e. Remove all occurrences of a token in a line, where that token is embedded in the line and is identified by a leading dash. What I'm trying to do here is to count the vowels in an arraylist of strings. What I did may not be right, but that's not my problem for now. My problem is that i cannot return the value (n) I want to return. GWT implements only a subset of the full Java JRE classes, and specifically implements nothing in java.io. To use java.io.Serializable as the GWT RPC serialization marker interface dilutes the message that java.io is not usable within a GWT application. Software Engineering for Ajax Using the Google Web Toolkit. Writing Java Code in Eclipse. In this case 'The import Composite cannot be resolved.' The problem is that we selected just the simple class name as the superclass in the New Java Class dialog, but Eclipse requires the full class name. I think we can make it safe but it would change the semantics of the current implementation. We could provide another comparator that does never fail. It is important to provide a safe API, i.e. One that does not throw unexpectedly at runtime. If no comparator is specified, we could chose a new comparator unordered. Even better would be to take the naturalComparator, if there exsists an order and the unordered comparator as fallback. But this is not possible in the case of empty collections where we can't take an element to check if it is comparable. Because of type erasure we are not a able to inspect the runtime element type of a collection. Also we can't take the naturalComparator by default and fall back to the unordered comparator because we would have internally to catch a ClassCastException which takes too much time. The static factory methods, e.g. TreeSet.empty() et al, could still use the naturalComparator. Only flatMap et al would need to use the unordered comparator by default. I think that is a good solution. If the API docs makes it clear how it works, with an additional example (downcasting to a Set and calling flatMap), this sounds like a reasonable solution. What do you think? Yes, great idea, I think it should be possible. Comparators are shared between different persistent versions of a collection. Get Serializer Cannot Be Resolved To Variable JavascriptEmpty collections never call the comparator. Once the element type is determined and therefore the comparator's state is initialized, the comparator can be shared between difference versions of the collection (e.g. Take(0) and then perend(elem) etc.). Regarding thread-safety I also see no problem. Even if parallel threads execute useNatural(), the returned value is defined in each case. I need to check if there are benefits when we make the instance variable volatile. Yes, this is evil. It can also occur when creating empty collections without specifying a Comparator. I think in practice it will be a rare case. However, it is still unsafe. Java is doing the same, e.g. In a SortedSet/Map we rely on specific behavior induced by the comparator, e.g. When calling min() and max(). The implementations of Traversable are overloaded there, relying on the RedBlackTree backend, which needs a comparator. Having no order will result in chaos. Also having a Comparator with 'no order', e.g. Comparison is always 0, is not a good idea in a Set. The RedBlackTree will contain at maximum 1 element then because it represents a Set and all elements are equal o_O. I cannot reproduce the problem with Java collections because there is no default collector that creates a SortedSet. In Java we can provoke the same, but it is not so easy to do the wrong thing as with Javaslang because we have to stream/collect forth and back and implement our own collector. Nevertheless, having a fallback that just works would be great. Fireworks animated gif white background. We cannot use a Comparator that returns 0 for all elements. Instead we can compare the hashCodes (with null values ordered first) as fallback. Even if there are situations that do not work (as Ruslan has shown), i favor to implement it similar to Benoits suggestion. I see no perfect solution. Any other thoughts? Just ran into this exact same issue and agree with most of what's been said here. My 2c on the issue: type erasure takes out a lot of good solutions. One available option is to change the signature of SortedSet flatMap(Function) in SortedSet to be Set flatMap(Function) and add a method SortedSet flatMapSorted(Function).
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |