For java/C# There is my code: Can I merge AddTable and AddCup into one method like Add<T> like this: The problem is that there are too many if else. Do you have any better suggestions? Answer Name the methods the same so that they will be overloads of each other: The compiler is smart enough to call the correct method.
Tag: syntactic-sugar
How does the Java ‘for each’ loop work?
Consider: What would the equivalent for loop look like without using the for each syntax? Answer Note that if you need to use i.remove(); in your loop, or access the actual iterator in some way, you cannot use the for ( : ) idiom, since the actual iterator is merely inferred. As was noted by Denis Bueno, this code works