Restricting T to string and int?

前端 未结 7 1470
悲哀的现实
悲哀的现实 2020-12-16 12:17

I have built myself a generic collection class which is defined like this.

public class StatisticItemHits{...}

This class can be

7条回答
  •  感动是毒
    2020-12-16 13:17

    You could make StatisticItemHits an abstract class and create two subclasses:

    StatisticItemHitsInt : StatisticItemHits{}

    StatisticItemHitsString : StatisticItemHits{}

    That way there can only be an int and string-representation of StatisticItemHits

提交回复
热议问题