4

I am using beanshell and i want to use arraylist

My code -

import java.util.*; 

List test= new ArrayList();
test.add("Last Name");

But I am getting following exception

Caused by: org.apache.bsf.BSFException: BeanShell script error:Typed variable declaration : 
Attempt to resolve method: add() on undefined variable or class name: test: at Line: 206

Any idea what is causing the problem?

Thanks

Coder
  • 3,090
  • 8
  • 49
  • 85
  • 1
    I tested the code in BeanShell itself, it works. why the exception message contains `org.apache.bsf.BSFException` – LiuYan 刘研 Jul 20 '12 at 02:26
  • I am using Liquid Office its a HP product. We use beanshell and javascript. Runs it tomact. May be thats why ? – Coder Jul 20 '12 at 02:28

2 Answers2

3

Try ArrayList test = new ArrayList(); That worked fine for me. Guess that the BeanShell doesn't work with polymorphism.

2

You need to define the type of the ArrayList. Here, you would do it like this:

List<String> test = new ArrayList<String>();
jrad
  • 3,172
  • 3
  • 22
  • 24