I have two different pieces of code. In one i need to use object and in the second i'm not. Can someone explain me the difference between the situation: first Code:
private val onInitWebResponseHandler: VolleyHandler.WebResponseHandler = VolleyHandler.WebResponseHandler() { Thread(ParseJsonStringOnInit(WeakReference(this), weakRefIOnAllScoresDataFirstFetched, it)).start() } Second Code:
val competitionOrderLevelComparator : Comparator<CompetitionObj> = object : Comparator<CompetitionObj> { override fun compare(object1: CompetitionObj, object2: CompetitionObj): Int { return object1.orderLevel - object2.orderLevel } } fun interface WebResponseHandler { fun onWebResponseFinished(jsonString:String?) } In addition how the first code, we can have () brackets if interface doesn't have a constructor?
VolleyHandler.WebResponseHandler()since it's an interfaceVolleyHandler.WebResponseHandler?VolleyHandler.WebResponseHandlercan't be an interface, as @Eitanos30 is able calling a constructor on it. A SAM would called (without constructor) likeSamInterface { ... }