RSS Amplifier

Aman Goyal · Dec 9, 2022

What I leaned this week?

0
Sign in to vote or save

This page cannot be shown here. You can still read it on the original site — the toolbar below keeps your place in the directory.

Quite an interesting week this was!! Specially for the fact that I learned new and interesting things. Starting from Generics in Java I have known generic classes in Java for quite some time now. But leaning about generic methods in non-generic class...

Quite an interesting week this was!! Specially for the fact that I learned new and interesting things.

Starting from Generics in Java

I have known generic classes in Java for quite some time now. But leaning about generic methods in non-generic classes was something new.

While working on a piece of code, I got the urge to know how the map method of stream api works? It was somehow taking a object of one tome and returns the object of completely different type, for me, I have had always written methods with fixed return type.. so I was curious to know how come map method was able to handle return of any type.

I looked at source code and this is what I found.

public interface Stream<T> extends BaseStream<T, Stream<T>> {
...

Stream class only has T type parameter hence It was confusing to se <R> in method signature of map function.

After some googling and tutorials and java docs .. I learned about generic methods in non generic classes.

Read on blog.amangoyal.ml

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.