![]() Sometimes, we want to temporarily enhance or extend the functions of objects without changing the class inheritance system. ![]() Reference code //Case: demonstrating dynamic blending Test the log() method in the main method, which makes the object of User class have Logger characteristics through object blending technology.Create a User class that has no relationship with the Logger attribute.Create a Logger attribute and add a log(msg:String) method.The so-called object blending refers to that in scala, there is no inheritance relationship between classes and traits, but through specific keywords, You can make this kind of object have members in a specified trait 2.1 syntax val/var Object name = new class with IdiosyncrasyĪt this time, we can consider using object blending technology. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |