function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sales Force FRMSales Force FRM 

Unable to compile example on set

Hi Folks,
                i am using set but i encountered following error , please refer my program:

1 public class SetDemo
2 {
3 Set<Integer> s = new Set<Integer>(); // Define a new set
4 s.add(1); // Add an element to the set
5 System.assert(s.contains(1)); // Assert that the set contains an element
6 s.remove(1); // Remove the element from the set
7 }


the compile error:

Error: Compile Error: unexpected token: 1 at line 4 column 7

TehNrdTehNrd
I couldn't see anything wrong with it and can reproduce this with summer 08. Definitely strange.

I get a slightly different error:

Code:
ERROR: Error: Compile Error: unexpected token: newSet.add at line 4 column 1

public class setDemo{

Set<Integer> newSet = new Set<Integer>();
newSet.add(1);

}

 



Message Edited by TehNrd on 05-21-2008 09:18 AM
TehNrdTehNrd
Answered here:

Variables can be defined in a class but any type of code must be in a method.

http://community.salesforce.com/sforce/board/message?board.id=apex&thread.id=4745


Message Edited by TehNrd on 05-21-2008 11:36 AM