Drocchio
Drocchio

Reputation: 413

what is the purpose of angle brackets in Kotlin after a method that should require a parenthesis?

On the official guide on RecyclerView, is written

recyclerView = findViewById<RecyclerView>(R.id.my_recycler_view).apply {
    // use this setting to improve performance if you know that changes
    // in content do not change the layout size of the RecyclerView
    setHasFixedSize(true)

    // use a linear layout manager
    layoutManager = viewManager

I cannot get the meaning of the angle bracket, my intuition is that they are similar to the keyword as, is that correct?

recyclerView =  view.findViewById<RecyclerView>(R.id.recycler_view) as RecyclerView

that I use in my Fragment( please notice the variable view

that I declarated into onCreateView

val view = inflater!!.inflate(R.layout.bezinning_fragment, container, false)

Upvotes: 3

Views: 1259

Answers (1)

Drocchio
Drocchio

Reputation: 413

found it! in this

post is clearly explained:

You're on API level 26, where the return type of findViewById is now a generic T instead of View and can therefore be inferred. You can see the relevant changelog here.

So you should be able to do this:

val recycler_view = findViewById(R.id.recycler_view) Or this:

val recycler_view: RecyclerView = findViewById(R.id.recycler_view)

Upvotes: 3

Related Questions