If you would like similar functionality for custom classes, you can add a constructor that takes a Map<String, Object>
and assign using that.
public class Student
{
private String firstName;
private String lastName;
private Integer grade;
public Student(Map<String, Object> initMap)
{
firstName = (String)initMap.get('firstName');
lastName = (String)initMap.get('lastName');
grade = (Integer)initMap.get('grade');
}
}
Student student1 = new Student(new Map<String, Object>{'firstName' => 'John',
'lastName' => 'Doe', 'grade' => 90});
Of course, this requires a decent amount of upkeep and can't really deal with bad keys or values until runtime, so it is probably not something you should plan on adding to every class. It could be useful for classes with lots of optional fields, though.