Java 8 Lambdas - equivalent of c# OfType -
I am now learning the features of the new Java 8, only 4 years later in the C # world, so for me the taller head But now I am struggling to find the equivalent of the "offtype" method of C #.
I have a list in myronodes, I want to get a list out of it, where the node is an interface, and it is implementing the specific node.
In C # this will be
ILIST
no exact Mail for in Java. OFTIP & lt; T & gt; ()
method, but you can use the filtering features of Java 8:
IList & lt; INode & gt; MyNodes = New Arrestist & lt; INode & gt; (); MyNodes.add (new specificNode ()); MyNodes.add (new node (new)); & Lt; SpecificNode & gt; FilteredList = myNodes.stream () .filter (x -> Examples of specific nodes) .map (n -> (specialnode) n) .collect (collectors list);
If you want to get clear artists, you can:
list & lt; Specific node & gt; FilteredList = myNodes.stream () .filter (SpecificNode.class :: isInstance) .map (SpecificNode.class :: cast) .collect (collectors list);
Comments
Post a Comment