Could a class be a first-class object? If yes, how would the syntax for dynamically creating new classes look like?


To narrow the question - how would you give this functionality while keeping language consistent?

For example how you create reference for new type. Do you make reference first-class object too and then use something like this:

Reference<newType> r = new Reference<newType>();
r.set(value);

Well this could get messy so you may just force user to use Object type references for dynamically created classes, but then you loose type-checking.

I think creating concise syntax for this is interesting problem which solving could lead to better language design, maybe language which is metalanguage for itself (I wonder if this is possible).

没有正确的解决方案

许可以下: CC-BY-SA归因
scroll top