EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

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  <20202021  2022  2023  2024  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  <20202021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: usage of Java Channel Access Client
From: "J. Lewis Muir via Tech-talk" <[email protected]>
To: 吴煊 <[email protected]>
Cc: tech-talk <[email protected]>
Date: Wed, 22 Jan 2020 16:01:00 -0600
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:Re: usage of Java Channel Access Client 吴煊 via Tech-talk
References:
usage of Java Channel Access Client 吴煊 via Tech-talk

Navigate by Date:
Prev: Re: EPICS_CA_MCAST_TTL equivalent for pvAccess James G Smedinghoff via Tech-talk
Next: Re: EPICS_CA_MCAST_TTL equivalent for pvAccess Michael Davidsaver 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  <20202021  2022  2023  2024 
Navigate by Thread:
Prev: usage of Java Channel Access Client 吴煊 via Tech-talk
Next: Re:Re: usage of Java Channel Access Client 吴煊 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  <20202021  2022  2023  2024 
ANJ, 23 Jan 2020 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·