Implementing a generic parameterized Java interface so that it satisfies (instance? ParameterizedType)

2016-08-04 Thread Jakub Holý
I need to implement the interface 
javax.websocket.MessageHandler.Whole - the type parameter is 
important since the Java code uses reflection to check 

 
whether the result is instanceof java.lang.reflect.ParameterizedType.

I believe I cannot use proxy or any other available Clojure mechanism as 
they do not support generics. Is that correct?

I believe that the only (and best) solution is to implement the interface 
in Java and then possibly extend the resulting class:

public class TextMessageHandler implements 
javax.websocket.MessageHandler.Whole {
public void onMessage(String message) {
}
}

(proxy [TextMessageHandler] []
(onMessage [msg]
  (println "received message(" (.getClass msg) "):" msg)))


Correct?

Thank you!

Cheers, Jakub Holý

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Implementing a generic parameterized Java interface so that it satisfies (instance? ParameterizedType)

2016-08-04 Thread Colin Fleming
Hi Jakub,

Yes, that is correct - Clojure interop only deals with raw classes, it has
no concept of generics. Java is the way to go here.

Cheers,
Colin

On 5 August 2016 at 09:28, Jakub Holý  wrote:

> I need to implement the interface javax.websocket.
> MessageHandler.Whole - the type parameter is important since the
> Java code uses reflection to check
> 
> whether the result is instanceof java.lang.reflect.ParameterizedType.
>
> I believe I cannot use proxy or any other available Clojure mechanism as
> they do not support generics. Is that correct?
>
> I believe that the only (and best) solution is to implement the interface
> in Java and then possibly extend the resulting class:
>
> public class TextMessageHandler implements 
> javax.websocket.MessageHandler.Whole
> {
> public void onMessage(String message) {
> }
> }
> 
> (proxy [TextMessageHandler] []
> (onMessage [msg]
>   (println "received message(" (.getClass msg) "):" msg)))
>
>
> Correct?
>
> Thank you!
>
> Cheers, Jakub Holý
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Implementing a generic parameterized Java interface so that it satisfies (instance? ParameterizedType)

2016-08-04 Thread Timothy Baldridge
I'd dig into it a bit more, since the JVM doesn't support generics either.
So if there's an api looking for some marker interfaces, it might be
possible to implement those interfaces as well. There's probably a way to
do this in pure Clojure.

On Thu, Aug 4, 2016 at 4:55 PM, Colin Fleming 
wrote:

> Hi Jakub,
>
> Yes, that is correct - Clojure interop only deals with raw classes, it has
> no concept of generics. Java is the way to go here.
>
> Cheers,
> Colin
>
> On 5 August 2016 at 09:28, Jakub Holý  wrote:
>
>> I need to implement the interface
>> javax.websocket.MessageHandler.Whole - the type parameter is
>> important since the Java code uses reflection to check
>> 
>> whether the result is instanceof java.lang.reflect.ParameterizedType.
>>
>> I believe I cannot use proxy or any other available Clojure mechanism as
>> they do not support generics. Is that correct?
>>
>> I believe that the only (and best) solution is to implement the interface
>> in Java and then possibly extend the resulting class:
>>
>> public class TextMessageHandler implements
>> javax.websocket.MessageHandler.Whole {
>> public void onMessage(String message) {
>> }
>> }
>> 
>> (proxy [TextMessageHandler] []
>> (onMessage [msg]
>>   (println "received message(" (.getClass msg) "):" msg)))
>>
>>
>> Correct?
>>
>> Thank you!
>>
>> Cheers, Jakub Holý
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
“One of the main causes of the fall of the Roman Empire was that–lacking
zero–they had no way to indicate successful termination of their C
programs.”
(Robert Firth)

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Implementing a generic parameterized Java interface so that it satisfies (instance? ParameterizedType)

2016-08-04 Thread Colin Fleming
The JVM does retain some generic information (see for example Neil Gafter's
Super Type Tokens), in particular Type instances can retain generic info
which is what the linked code is using. It might be possible to recreate
this in pure Clojure but IMO it's likely to be more difficult than it's
worth - all the reflective Type code is very fiddly. YMMV, of course.

On 5 August 2016 at 11:18, Timothy Baldridge  wrote:

> I'd dig into it a bit more, since the JVM doesn't support generics either.
> So if there's an api looking for some marker interfaces, it might be
> possible to implement those interfaces as well. There's probably a way to
> do this in pure Clojure.
>
> On Thu, Aug 4, 2016 at 4:55 PM, Colin Fleming  > wrote:
>
>> Hi Jakub,
>>
>> Yes, that is correct - Clojure interop only deals with raw classes, it
>> has no concept of generics. Java is the way to go here.
>>
>> Cheers,
>> Colin
>>
>> On 5 August 2016 at 09:28, Jakub Holý  wrote:
>>
>>> I need to implement the interface javax.websocket.
>>> MessageHandler.Whole - the type parameter is important since
>>> the Java code uses reflection to check
>>> 
>>> whether the result is instanceof java.lang.reflect.ParameterizedType.
>>>
>>> I believe I cannot use proxy or any other available Clojure mechanism
>>> as they do not support generics. Is that correct?
>>>
>>> I believe that the only (and best) solution is to implement the
>>> interface in Java and then possibly extend the resulting class:
>>>
>>> public class TextMessageHandler implements 
>>> javax.websocket.MessageHandler.Whole
>>> {
>>> public void onMessage(String message) {
>>> }
>>> }
>>> 
>>> (proxy [TextMessageHandler] []
>>> (onMessage [msg]
>>>   (println "received message(" (.getClass msg) "):" msg)))
>>>
>>>
>>> Correct?
>>>
>>> Thank you!
>>>
>>> Cheers, Jakub Holý
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to clojure@googlegroups.com
>>> Note that posts from new members are moderated - please be patient with
>>> your first post.
>>> To unsubscribe from this group, send email to
>>> clojure+unsubscr...@googlegroups.com
>>> For more options, visit this group at
>>> http://groups.google.com/group/clojure?hl=en
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to clojure+unsubscr...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clojure@googlegroups.com
>> Note that posts from new members are moderated - please be patient with
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+unsubscr...@googlegroups.com
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> ---
>> You received this message because you are subscribed to the Google Groups
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to clojure+unsubscr...@googlegroups.com.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> “One of the main causes of the fall of the Roman Empire was that–lacking
> zero–they had no way to indicate successful termination of their C
> programs.”
> (Robert Firth)
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
> ---
> You received this message because you are subscribed to the Google Groups
> "Clojure" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to clojure+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 

Re: Implementing a generic parameterized Java interface so that it satisfies (instance? ParameterizedType)

2016-08-05 Thread Jakub Holý
Thanks a lot, Colin! It is good to get my beliefs confirmed :-)

(And you too, tbc++, for contributing!)

On Friday, August 5, 2016 at 3:30:22 AM UTC+2, Colin Fleming wrote:
>
> The JVM does retain some generic information (see for example Neil 
> Gafter's Super Type Tokens), in particular Type instances can retain 
> generic info which is what the linked code is using. It might be possible 
> to recreate this in pure Clojure but IMO it's likely to be more difficult 
> than it's worth - all the reflective Type code is very fiddly. YMMV, of 
> course.
>
> On 5 August 2016 at 11:18, Timothy Baldridge  > wrote:
>
>> I'd dig into it a bit more, since the JVM doesn't support generics 
>> either. So if there's an api looking for some marker interfaces, it might 
>> be possible to implement those interfaces as well. There's probably a way 
>> to do this in pure Clojure.
>>
>> On Thu, Aug 4, 2016 at 4:55 PM, Colin Fleming > > wrote:
>>
>>> Hi Jakub,
>>>
>>> Yes, that is correct - Clojure interop only deals with raw classes, it 
>>> has no concept of generics. Java is the way to go here.
>>>
>>> Cheers,
>>> Colin
>>>
>>> On 5 August 2016 at 09:28, Jakub Holý 
>>> > wrote:
>>>
 I need to implement the interface 
 javax.websocket.MessageHandler.Whole - the type parameter is 
 important since the Java code uses reflection to check 
 
  
 whether the result is instanceof java.lang.reflect.ParameterizedType.

 I believe I cannot use proxy or any other available Clojure mechanism 
 as they do not support generics. Is that correct?

 I believe that the only (and best) solution is to implement the 
 interface in Java and then possibly extend the resulting class:

 public class TextMessageHandler implements 
 javax.websocket.MessageHandler.Whole {
 public void onMessage(String message) {
 }
 }
 
 (proxy [TextMessageHandler] []
 (onMessage [msg]
   (println "received message(" (.getClass msg) "):" msg)))


 Correct?

 Thank you!

 Cheers, Jakub Holý

 -- 
 You received this message because you are subscribed to the Google
 Groups "Clojure" group.
 To post to this group, send email to clo...@googlegroups.com 
 
 Note that posts from new members are moderated - please be patient with 
 your first post.
 To unsubscribe from this group, send email to
 clojure+u...@googlegroups.com 
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en
 --- 
 You received this message because you are subscribed to the Google 
 Groups "Clojure" group.
 To unsubscribe from this group and stop receiving emails from it, send 
 an email to clojure+u...@googlegroups.com .
 For more options, visit https://groups.google.com/d/optout.

>>>
>>> -- 
>>> You received this message because you are subscribed to the Google
>>> Groups "Clojure" group.
>>> To post to this group, send email to clo...@googlegroups.com 
>>> 
>>> Note that posts from new members are moderated - please be patient with 
>>> your first post.
>>> To unsubscribe from this group, send email to
>>> clojure+u...@googlegroups.com 
>>> For more options, visit this group at
>>> http://groups.google.com/group/clojure?hl=en
>>> --- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "Clojure" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to clojure+u...@googlegroups.com .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>
>>
>> -- 
>> “One of the main causes of the fall of the Roman Empire was that–lacking 
>> zero–they had no way to indicate successful termination of their C 
>> programs.”
>> (Robert Firth) 
>>
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@googlegroups.com 
>> 
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com 
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> --- 
>> You received this message because you are subscribed to the Google Groups 
>> "Clojure" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from t