-1

Earlier I have model class in java which uses autovalue. Now, it's converted to Kotlin data class.

Model Class -->

public static SampleClass create(
@NonNull final SamplePost post,
@NonNull final List<SampleComment> comments) {
return new AutoValue_SampleClass(post, comments);
}

Calling Class -->

return Observable.zip(...

                    SampleClass::create);
          }

new data class -->

data class SampleClass(val post: DiscussionPost,
                       val comments: List<SampleComment>) : Parcelable

Now how to call it for data class?

Praful Ranjan
  • 117
  • 1
  • 2
  • 13

2 Answers2

5

U can use SampleClass::new to call the constructor.

ebasha
  • 422
  • 2
  • 4
1

If I understand correctly, you don't need a constructor call, but a constructor reference. The syntax for it is ::SampleClass. But this may not trigger SAM conversion, in which case you'll need

 Observable.zip(...,
                { post, comments -> SampleClass(post, comments) })

EDIT: The above assumes that zip is called from Kotlin, if you want to call it from Java, see @ebasha's answer.

Alexey Romanov
  • 167,066
  • 35
  • 309
  • 487