Search code examples
javajavaparser

JavaParser add ArrayList<String> as method return type


I'm trying to create a new method using the JavaParser API below, where I need to define my method return type. My method return type is ArrayList<String>. I'm wondering if anyone knows how it is possible to create such a method return type, which needs to have this Type?

MethodDeclaration method = new MethodDeclaration(modifiers, returnType, methodName);


Solution

  • You can create Type as below:

    ClassOrInterfaceType returnType = JavaParser.parseClassOrInterfaceType("ArrayList<String>");