lundi 27 février 2017

Java equivalent of C# code

I'm trying to rewrite some very old C# (.Net 2.0) code of mine into Java. Program is simple but i stumbled upon this part which i have no idea how to transfer into java:

public ISomething listContainsType(Type typeToCheck) {
        foreach(ISomething obj in _List)
            if (obj.GetType() == typeToCheck)
                return obj;

        return null;
    }

So, code above goes through list knowing only that each element implements "ISomething" and checks which class actually implements said interface. At least, that how it worked with .Net 2.0.

What would be Java equivalent of code above?

I know that above lines give that "code smell" but before refactoring i would like to rewrite it "as is" so i can test final product using the same testing methods.





Aucun commentaire:

Enregistrer un commentaire