Let us not proceed and check out one more concept in case of Cartan such as Date classes and also in
the previous video we learn that Bideford Every class has a superclass of any and this class of any
provides the functions are emitters such as equals method hash for the method and also to string method.
So all these methods are by default present in every class that we define inside the Cartland file.
And now proceeding forward when we use the data classes the Cartland simply provides a copy method for
us that we will check out.
Inside the demo video.
And now they're Dudack classes simply provides these mentioned metters implementation so we can make
effective use of these methods inside their classes.
Navar does this data classes dance for.
Check it out.
So here inside the 80 I have a class of user.
Now as a field variable are the property of the user.
I will simply define the name and ID.
So here I have simply defined the property name and also ID on the student or the user.
Right.
And now inside the main function I will simply define two objects of the user.
So here I have used an end user two.
If you are just here I have a user name as Sam and here Sam as well.
I and then here as well.
So both these user and user 2 has the same name and same ID.
Now if I compare let's say User 1 equal to equal to user 2 then simply print out equal is not equal.
So let us note in the code.
So in the output we have not equal.
Now you must be wondering that these two values are the same Sam.
Dan Santon so why not use that have an end user to equal.
Just because here we are simply creating two objects.
And these are actually two differences.
So these are two different objects created inside the heap memory.
So here we are actually comparing the object reference.
So both are in this case are different.
Right.
So that is why we get not equal in case of Cartland.
Now in case of Djala as well if you are from a Java background then you must be doing what I'm talking
about.
Then we create user and user.
It simply creates two different objects.
But with the same value.
And now if I change this class with the help of a keyword of data let's say a data base class user and
now like I said in the code.
And now in the output.
So will we have equal in the output.
No this is simply because the purpose of the class is just to deal with data not the objects.
So here when we compare the use of an end user to it simply compares the values such as Sam then Sam
then search simply prints out equal in the output console.
So this is the beauty of using data.
Then you want to only deal with their data or you want to compare their data then simply use their data
keyword in case of class.
Right.
And now suppose if I print here let's see lane use one dog string right like this or even if we don't
use to string then also so let's see what happens.
Now here let us first remove their data keyword.
Let us note in the code.
So in the output we have some address of the object of user Gandara Mike or Lindora do use some address
location of this user object right now.
If I use the data keyword here and now let us run the code.
So this time this trendline user is simply printing or the value of this user that is name equal to
sign an ID equal to 10.
So here implicitly we are actually calling to string method.
Let us run the court again.
So here we go the same output is actually present here.
So by default this data class actually provides their default implementation of their two string method
which is actually the part of the any class which is the superclass of any classes in case of Cartland.
Right.
So that is why we are getting the value and now presenting forward here down the side leg we show you
the copy method.
So that let's say new user equal to use it when dart copy Metford.
Now here I can simply use new user equal to use the rendered copy elaters printed and let us note in
the chord so in the output we have the value of the new user.
Again namea quite the same and equal to 10.
So we are perfectly able to copy from their data from one user and then putting it inside the new reference
of new user.
Right.
And now suppose I'm on the override such as the value of Sam let's say it to Peter.
So I would simply use name equal to.
Let's see.
Peter and now there are just called.
So in the output we have the name as Peter.
But the idea is still remaining C that is then.
So in this way you can simply change the value of the variable such as name while copying the use that
object to an adder.
Right.
And I suppose if you want you can also use let's say 80 equal to 25 something like that.
Right.
So you can simply change the values.
And if you want to change the sequence then you can simply change it by simply using the equal to let's
say grade 5.
Let us note in the code.
So here this time the ighly will be changed but the name will remain Samm like this.
The name is Sam but the ID is now changed to 25.
Now notice here that we are using the named leaders.
Now the concept of named barometers.
We already saw in the previous Marty when we talked about functions in case of Coughlin.
So if you are simply defining the name of the speedometer as ighly equal to the value.
So no matter what is a sequence.
If you defined the name bit weaker than this value will only fall here in spite of the first bit weaker
remains the name.
And here the first parameter is ID so the ID will simply match with this ID and this ID value will be
overridden from end to 25.
Like this.
Right.
And now at the end of this video let me show you something is does not move this that keyword.
So here it shows an error that in case of day that is that primary constructor should only contain the
property be it on meters.
So it says either that or either.
Well it cannot contain the.
I.
Right.
So always remember in case of that last is the primary constructor it should only contain the property
variables such as that are valid.
So this was all about this video of the glasses.
So thanks for watching and have a good day.