Hi Lewis,
Thanks for your reply. Could you give me an elegant way of example to call put method. It seems like that I need to create channel for 300 times by what you said.
Cheers,
Xuan
在 2020-01-23 06:01:00,"J. Lewis Muir" <[email protected]> 写道:
>On 01/22, 吴煊 via Tech-talk wrote:
>> My question is how to use each channel to put value? I've not found any example. I have tried: channels.get(0).put("test"), it's not correct.(error info:The method put(capture#1-of ?) in the type Channel<capture#1-of ?> is not applicable for the arguments (String))
>
>That put method is just going to be awkward to use when the type of the
>object it's called on is Channel<?> (i.e., a Channel of some type).
>There are some other methods on Channel that you could call without
>trouble, but put(T) will be problematic because its argument is of type
>T and the object you're calling it on is a Channel of some type, not
>necessarily type T. If you have to call that method, the best you can
>do is cast the Channel<?> object to the correct type, Channel<String> in
>your example:
>
> (Channel<String>(channels.get(0))).put("test");
>
>But that's ugly, and you're throwing away all of the benefits of
>generics (e.g., type safety and expressiveness). You'd also have to add
>a @SuppressWarnings("unchecked") annotation to the method, or change
>the code to a local variable assignment and put the annotation on the
>variable, to get rid of the compiler warning.
>
>So, I'd say that you'd be better off not trying to call that put(T)
>method like that. Instead, stick to only calling methods on those
>channels that you can call in a type-safe way.
>
>If you really need some way to do what you're trying to do, you'd
>probably want something added to the ca API to help with that.
>
>If you have to do it yourself, though, you could create your own
>container object that could hold Channel instances and that could
>provide a get and put method that took a type token. Then, assuming
>"channels" was an instance of this container object, your example could
>become something like this:
>
> channels.put(0, String.class, "test");
>
>Of course, there are various designs you could come up with.
>
>Lewis
- Replies:
- Re: usage of Java Channel Access Client Simon Rees via Tech-talk
- References:
- usage of Java Channel Access Client 吴煊 via Tech-talk
- Re: usage of Java Channel Access Client J. Lewis Muir via Tech-talk
- Navigate by Date:
- Prev:
Re: EPICS_CA_MCAST_TTL equivalent for pvAccess Pierrick M Hanlet via Tech-talk
- Next:
Read/Write waveforms using Channel Access C API Abdalla Ahmad via Tech-talk
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
<2020>
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
Re: usage of Java Channel Access Client J. Lewis Muir via Tech-talk
- Next:
Re: usage of Java Channel Access Client Simon Rees via Tech-talk
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
<2020>
2021
2022
2023
2024
|