chaokunyang commented on issue #1683:
URL: https://github.com/apache/fury/issues/1683#issuecomment-2171736538

   Scala didn't provide a method to construct object with default value at 
bytecode level. It generate bytecode to invoke constructor with all parameters 
provided, and default params are provided at callsite. 
   
   If we need to provide default value when creating object, we need to extract 
the default value. Fortunately, scala generate a 
   method like `SomeClass$.apply$default$2:()I`:
   
   ```scala
   case class SomeClass(v: List[IdAnyVal], x:Int=1)
   
   // Callsite bytecode
         34: getstatic     #131                // Field 
org/apache/fury/serializer/SomeClass$.MODULE$:Lorg/apache/fury/serializer/SomeClass$;
         37: invokevirtual #135                // Method 
org/apache/fury/serializer/SomeClass$.apply$default$2:()I
         40: invokespecial #138                // Method 
org/apache/fury/serializer/SomeClass."<init>":(Lscala/collection/immutable/List;I)V
         43: putstatic     #87                 // Field 
p:Lorg/apache/fury/serializer/SomeClass;
         46: getstatic     #143                // Field 
scala/Predef$.MODULE$:Lscala/Predef$;
   ```
   
   We may can detect whether such method exists to know which parameter has 
default value, and provide it as default value when constructing object. This 
will take some horse work. We don't have time for this currently. Would you 
like to contribute to this? The `record` contructor in Fury 
`org.apache.fury.builder.ObjectCodecBuilder#createRecord/org.apache.fury.serializer.ObjectSerializer#read`
 can be taken as an example.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to