存在着一个undocumented syntax执行物业类型:
classdef Packet
properties
[email protected]
[email protected] = uint16(0);
[email protected]
end
end
如果您尝试设置了错误类型的属性,你会得到一个错误:
>> p = Packet;
>> p.PacketType = 'tcp';
>> p.HeaderLength = 100;
While setting the 'HeaderLength' property of Packet:
Value must be 'uint16'.
据我所知,此语法支持所有基本类型,如:char, int32, double, struct, cell, ...
,除了任何用户定义的(只使用任何类名)。
请注意,如上所述设置类型似乎会覆盖任何“设置方法”(如果有)。
我只是碰到这种语法在R2013a一个内部类(toolboxdir('matlab')\graphics\+graphics\+internal\+figfile\@FigFile\FigFile.m
)被使用来了,但它也曾在R2012a,可能更早的版本,以及...
这是一个整洁的发现! – Jonas
[交叉引用](http://undocumentedmatlab.com/blog/setting-class-property-types) –
@YairAltman:再次感谢您在博客上发布了一篇专门文章 – Amro