No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
Newer Version Available
Casting ConnectApi Objects
It may be useful to downcast some ConnectApi output objects to a more
specific type.
This technique is especially useful for message segments, feed item capabilities, and record fields. Message segments in a feed item are typed as ConnectApi.MessageSegment. Feed item capabilities are typed as ConnectApi.FeedItemCapability. Record fields are typed as ConnectApi.AbstractRecordField. These classes are all abstract and have several concrete subclasses. At runtime you can use instanceof to check the concrete types of these objects and then safely proceed with the corresponding downcast. When you downcast, you must have a default case that handles unknown subclasses.
The following example downcasts a ConnectApi.MessageSegment to a ConnectApi.MentionSegment:
1if(segment instanceof ConnectApi.MentionSegment) {
2 ConnectApi.MentionSegment = (ConnectApi.MentionSegment)segment;
3}