-
Notifications
You must be signed in to change notification settings - Fork 25
Custom Features
qtiuto edited this page Jan 1, 2019
·
3 revisions
An Object can be call with a table to set its fields. Given a class like
class A{
public int idx;
public String str;
}then
local a=A(){idx=3,str='ggg'}is equivalent to
local a=A();
a.idx=3
a.str='ggg'Never use this syntax with List and its implementation types,ArrayList(){1,2,4} won't work. Use ArrayList{1,2,4} instead. However, you can use things like HashMap(){r=4,g=5,b=6}. However, I still advise to use constructor syntax rather than Object call. This feature is for Bean class.
To allocate a Bean class, you can use sun.misc.unsafe to achieve your goal.
-
Add a custom lua function as a object method is allowed. The syntax is followed
using 'java.lang'
Object.kk= function(obj,...)--... stands for args,ojb stands for the instance
print(...)
end
Object().kk(2,3,5) -- prints 2 3 5Note
- Only object method will be add.
- The method is add to the type.
- The method is only available for current thread.
- The method won't be remove until its thread dies.
- The method is only available for lua code. Java side will never notice them.
- Never type code like
Object.kk=function() end; Object.kk()
These features are inspired by c#, so I doesn't advice you to use them for java code.