public class Person { private String name; private Integer age; } public class PersonServiceImpl implements PersonService { public void changeAge(Integer personId, Integer newAge) { Person person = em.getReference(Person.class, personId); // person is a proxy person.setAge(newAge); } }
final Person person = myself; person = otherPerson; //Invalid person.setAge(20); //Valid!
import org.json.JSONObject; public class JsonTest { public static void main( String[] args ) { Person person = new Person(); person.setName( "Person Name" ); person.setAge( 666 ); JSONObject jsonObj = new JSONObject( person ); System.out.println( jsonObj ); } }
p.setAge(18); p.setHappy(false); kieSession.update(fh, p);
try { final Person p = new Person( "person" ); p.setAge( 2 ); FactHandle h = ksession.insert( p ); assertEquals(1,
try { final Person p = new Person( "person" ); p.setAge( 2 ); FactHandle h = ksession.insert( p ); assertEquals(1,
ksession.fireAllRules(); mario.setAge(35); ksession.update(fh_mario, mario, "age");
public class MyActivity extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Person me = new Person(); me.setAge(22); //feels old }
ksession.fireAllRules(); mario.setAge(35); ksession.update(fh_mario, mario, "age");
@Test(expected = IllegalArgumentException.class) public void testWHetherInputValid() { Person p = new Person(); int invalidAge = -1; p.setAge(invalidAge); }
Person person1 = new Person(); // Creates a Person instance person1.setAge(10); // Sets person1's age to 10 Person person2 = new Person(); // Creates a separate Person instance person2.setAge(person1.getAge()); // Sets person2's age to 10 person1.setAge(30); // Sets person1's age to 30; no effect on person2 System.out.println(person2.getAge()); // Shows person2's age (10)
//Declare with List instead of ArrayList List<Person> people = new ArrayList<Person>(); for(i = 0; i< 3; i++){ Person p = new Person();// Move this line here. p.setName("Jon"); // Read attribute from file p.setAge(33); people.add(p);//Index should not mentioned .... }
public void changePersonObject(Person p){ p.setAge(100); p.setFirstName("Lost"); p.setLastName("Boy"); }
private static Person readPerson(String line) { String[] columns = line.split(","); Person newPerson = new Person(); newPerson.setName(columns[0]); newPerson.setSex(columns[1]); newPerson.setAge(columns[2]); newPerson.setBirth(columns[3]); return newPerson; }
for (int i = 0; i < studentItems.size(); i++) { Student student = studentItems.get(i); Person person = new Person(); person.setName(student.getName()); person.setAge(student.getAge()); // person.setGrade(computeGradeSomehow()); - set grade here persons[i] = person; }