I use a librery that is writed by kotlin in android studio project
class Builder<S> private constructor(val dateSelector: DateSelector<S>) {
var calendarConstraints: CalendarConstraints? =null
/** Sets the first, last, and starting [Month]. */
fun setCalendarConstraints(bounds: CalendarConstraints?): Builder<S> {
calendarConstraints = bounds
return this
}
/** Creates a [MaterialDatePicker] with the provided options. */
companion object {
/**
* Used to create a Builder that allows for choosing a single date in the `MaterialDatePicker`.
*/
fun datePicker(): Builder<Long?> {
return Builder(SingleDateSelector())
}
}
}
when i want to use setCalendarConstraints in java class activity
MaterialDatePicker.Builder.Companion.datePicker().setTitleText(R.string.selectdate).setCalendarConstraints(constraints).build();
i have this error for when call setCalendarConstraints
Ambiguous method call. Both setCalendarConstraints (CalendarConstraints) in Builder and setCalendarConstraints (CalendarConstraints) in Builder match
which i can split default setter and fun in java?
CodePudding user response:
If you have access to the library, I guess only the following alternative options can help, modifying the source code of the library:
Make
calendarConstraintsproperty private.Rename
calendarConstraintsproperty to something else.Rename
setCalendarConstraintsmethod to something else.Add some additional parameter to
setCalendarConstraintsmethod.Add
@JvmFieldannotation tocalendarConstraintsproperty:@JvmField var calendarConstraints: CalendarConstraints? = null
Or you can use Kotlin instead of Java in the project where you are working with this library.
CodePudding user response:
Try this if it helps
Builder<Long> materialDatePickerBuilder = MaterialDatePicker.Builder.Companion.datePicker();
materialDatePickerBuilder.setTitleText(R.string.selectdate);
materialDatePickerBuilder.setCalendarConstraints(constraints);
// pass materialDatePickerBuilder.build() whenever you need it
