Could I access to a subclass properties (values) from superclass?
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Rafa Carbonell
am 13 Dez. 2022
Kommentiert: Rafa Carbonell
am 13 Dez. 2022
I want to implement the concept of hashCode on the object like Java. https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/Object.html
So, I don't know if it possible to access to all properties of subclass.
I know that I could access to public properties of the object listing with the command of properties.
I would like to extend the captabilites of Containers.Map (MATLAB) to represent a Set with objects, not only with arrays of numbers, dates, times, or text data, so implementing a hashCode with a number like Java, I think that is the correct way.
So, listing all properties of the object, and computing a hashCode with simple properties like integer, float and string or chars.
https://www.mathworks.com/help/matlab/set-operations.html
0 Kommentare
Akzeptierte Antwort
Steven Lord
am 13 Dez. 2022
So, I don't know if it possible to access to all properties of subclass.
Superclasses should not know about the properties of their subclasses. They shouldn't depend on whether or not anyone inherits from them or how many subclasses inherit from them.
I would like to extend the captabilites of Containers.Map (MATLAB) to represent a Set with objects, not only with arrays of numbers, dates, times, or text data, so implementing a hashCode with a number like Java, I think that is the correct way.
Rather than reinventing the wheel, why not use the dictionary object introduced in release R2022b? For using custom objects with dictionary those class authors can define keyHash and keyMatch methods for those objects as shown on this documentation page.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Java Package Integration finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!