Skip to content

Java arraylist and velocity arraylist behave differently #27

@developer-sunnywu

Description

@developer-sunnywu

Description:

I try to use custom function return arraylist and here is my function in java


    private static Map<String, List<String>> map = Map.of(
            "Long", Arrays.asList("null", "1", "2"),
            "Boolean", Arrays.asList("null", "True", "False"),
            "BigDecimal", Arrays.asList("null", "BigDecimal.ZERO", "BigDecimal.ONE"),
            "LocalTime", Arrays.asList("null", "LocalTime.of(0, 0, 0)", "LocalTime.of(1, 1, 1)")
    );

    public static ArrayList<String> getValuesByFieldName(String filedName) {
        return new ArrayList<>(map.get(filedName));
    }
}

And there is my velocity.vm

#set($FieldUtil = $loader.loadClass("com.example.codegenerator.telosys.util.FieldUtil"))
#set($myJavaList = $FieldUtil.getValuesByFieldName('Long'))
$myJavaList.class.name
$myJavaList
### Will throw no attribute '['
$myJavaList[0]


#set( $mylist = [1, 2, 3, "A", true, 65.78] )
$mylist.class.name
$mylist
### It is okay here
$mylist[0]

I find that even though they have same type(java.util.ArrayList), the myJavaList not work

Version use: telosys-cli-4.1.1-001

Expected behaviour
I expect they can both use the same operator which I can access the element using bracket notation here. Hope I specify the problem clearly

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions