Skip to content

ArrayList constructor is not called properly #83

@EmilyGraceSeville7cf

Description

@EmilyGraceSeville7cf

My goal is to copy items from the first list to the second, while when I call public ArrayList(Collection<? extends E> c) constructor it doesn't copy the first's list items.

type
  ArrayListT = java_util_ArrayList;

var
  list: ArrayListT;
  list2: ArrayListT;

function NewArrayList(): ArrayListT;
var
  result: ArrayListT;
  
begin
  New(result);
  NewArrayList := result;
end;

function NewArrayList(other: ArrayListT): ArrayListT; // corresponding Java constructor: public ArrayList(Collection<? extends E> c)
var
  result: ArrayListT;

begin
  New(result, other);
  NewArrayList := result;
end;

begin
  list := NewArrayList();
  list.add(1);
  list2 := NewArrayList(list);
  Writeln(list);
  Writeln(list2); // list2 is expected to have [1] elements instead of none
end.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions