[PATCH] 4851444: Exposing sun.reflect.Reflection#getCallerClass as a public API in Java 8
Jochen Theodorou
blackdrag at gmx.org
Fri Sep 20 21:46:04 UTC 2013
Am 20.09.2013 20:46, schrieb Mandy Chung:
[...]
> Exposing a StackStream API means that you need to eagerly walk the stack
> and copy the stack frames to it before it returns. I agree it is a much
> more flexible API. On the other hand, stack walking is sequential and
> ordered and a stack stream will be traversed as in an iterator.
not the StackStream API, I did mean a Stream as in
http://download.java.net/lambda/b78/docs/api/java/util/stream/Stream.html But
I must say, I did not realize Stream has so little to offer in terms of
default implementations. I am not saying using this class is a good
idea, but if you already go on lambdas, then this should be at least
something to consider... and to underline it: Stream does not require
you to eagerly read all values
> What about a findCaller method that takes a parameter to indicate how
> many times you skip over the matching elements before applying the
> function:
>
> Thread.findCaller(info -> {return
> !haveToSkip(info.getDeclaringClass());},
> nonSkippedFramesDepth,
> StackFrameInfo::getDeclaringClass());
just to show you how this could work with the Stream
Thread.getStackStream().
filter(info -> {return !haveToSkip(info.getDeclaringClass());}.
subStream(nonSkippedFramesDepth).
map(StackFrameInfo::getDeclaringClass).findFirst()
I am looking at those things since only recently, so there is surely a
better way, but have an impression it should be enough. Especially I
show this to you, so you can see that with a Stream no new method is needed.
bye Jochen
--
Jochen "blackdrag" Theodorou - Groovy Project Tech Lead
blog: http://blackdragsview.blogspot.com/
german groovy discussion newsgroup: de.comp.lang.misc
For Groovy programming sources visit http://groovy-lang.org
More information about the core-libs-dev
mailing list