Could I access to a subclass properties (values) from superclass?

3 Ansichten (letzte 30 Tage)
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

Akzeptierte Antwort

Steven Lord
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.
  1 Kommentar
Rafa Carbonell
Rafa Carbonell am 13 Dez. 2022
Thanks for your answer! Nowadays, I don't have MATLAB R2022b, but I will download it. In previous versions, dictionaries did not exist.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

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!

Translated by