Retrieve constant property from class handle reference

조회 수: 3 (최근 30일)
Chris Warwick
Chris Warwick 2017년 12월 7일
댓글: Guillaume 2017년 12월 11일
I have a class myClass which inherits from the handle object and has a constant property:
classdef myClass < handle
properties(Constant)
myProp = 'abc';
end
end
I have a reference to the class: ref = @myClass
How do I retrieve 'myProp' from 'ref' without instantiating the class?

답변 (1개)

Adam
Adam 2017년 12월 7일
myClass.myProp
will give you the constant property, you don't need an instance of it.
ref = @myClass
is a function handle to the constructor of the class, not a reference to the class, but either way is irrelevant to getting a constant property.
  댓글 수: 2
Chris Warwick
Chris Warwick 2017년 12월 11일
I'm aware of myClass.myProp working, but that's not helping when I want to generalize the reference to any class in a 'super-class'. If @myClass is just a reference to the constructor though then it seems like it can't be done.
Guillaume
Guillaume 2017년 12월 11일
Matlab does not really have references. It would much easier to help you if we knew what it is you're trying to achieve.

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by