我想通过其名称动态访问类的属性。我知道使用反射可能。但我想知道Kotlin是否具有类似于Javascript的内容:
var mutualFriendsNames = db.Users
.Where(u =>
db.FriendShips.Any(f => f.FriendId == u.Id && f.UserId == 1) &&
db.FriendShips.Any(f => f.FriendId == u.Id && f.UserId == 2))
.Select(p => p.Name);
或者像在python中一样:
var mutualFriendsNames = db.Users
.Where(u =>
db.FriendShips.Any(f =>
(f.FriendId == u.Id && f.UserId == 1) ||
(f.FriendId == 1 && f.UserId == u.Id)) &&
db.FriendShips.Any(f =>
(f.FriendId == u.Id && f.UserId == 2) ||
(f.FriendId == 2 && f.UserId == u.Id)))
.Select(p => p.Name);
所以我想这是当前的方法,谢谢Syed Ahmed Jamil:
Object['propertyname'] = "new value"