如何启动泛型类型[重复](How to initiate generic type [duplicate])
这个问题在这里已有答案:
- 在Java中创建泛型类型的实例? 23个答案
public interface myInterface<T> { public List<T> doWork(); } public abstract class baseClass<T> implements myInterface<T>{ protected T obj; protected List<T> list; public baseClass<T>(){ //how do I initiate obj? //how do I initiate list? } } public class myClassA extends baseClass<T> { public List<T> doWork() }
我有这个代码,我想知道如何动态地启动obj和类型T的列表。
This question already has an answer here:
- Create instance of generic type in Java? 25 answers
public interface myInterface<T> { public List<T> doWork(); } public abstract class baseClass<T> implements myInterface<T>{ protected T obj; protected List<T> list; public baseClass<T>(){ //how do I initiate obj? //how do I initiate list? } } public class myClassA extends baseClass<T> { public List<T> doWork() }
I have this code and I was wondering how I could initiate obj and list of type T dynamically.
原文:https://stackoverflow.com/questions/16160053
更新时间:2023-08-18 22:08
最满意答案
如果你用14个逗号作为13个逗号,那么这将起作用:
SELECT * FROM table WHERE column LIKE '%,%,%,%,%,%,%,%,%,%,%,%,%,%'
%
匹配任何字符串(包括零长度)。If you count a string with 14 commas as having 13 commas, then this will work:
SELECT * FROM table WHERE column LIKE '%,%,%,%,%,%,%,%,%,%,%,%,%,%'
%
matches any string (including zero length).
相关问答
更多-
解析包含逗号的字符串项目的逗号分隔字符串(Parsing a comma-delimited string that contains string items that contain commas)[2021-12-24]
我不知道你的目标语言是什么,但一般的做法是一次读一个字符,像往常一样用逗号分开。 但是,如果遇到"作为新项目的第一个字符,您设置了一个标志(如in_quotes )。如果设置了该标志,则会读取所有字符,直到下一个" ,此时您将该标志设置为false。 I don't know what language you are targeting, but the general approach is to read one character at a time, splitting at commas as ... -
如果你用14个逗号作为13个逗号,那么这将起作用: SELECT * FROM table WHERE column LIKE '%,%,%,%,%,%,%,%,%,%,%,%,%,%' %匹配任何字符串(包括零长度)。 If you count a string with 14 commas as having 13 commas, then this will work: SELECT * FROM table WHERE column LIKE '%,%,%,%,%,%,%,%,%,%,%,%,%, ...
-
没有办法做到这一点。 更糟糕的是:在SQL中,有可能使用IN子句获取主题,但是使用linq,你甚至没有获得该选项。 我担心剩下的是一个艰苦的linq-to-objects操作,你首先从数据库中获取Student ,然后在int数组中解析主题,最后使用Contains查询获取Subject : var subjectIds = student.Subjects .Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries) .S ...
-
我会将任务分成两部分: 用逗号分隔字符串 仅取前N个值 幸运的是,C#使这两个都非常简单, String.Split处理第一个,而LINQ Take方法处理第二个: var items = text.Split(',') .Take(itemLimit); 或者,如果要创建列表: var items = text.Split(',') .Take(itemLimit) .ToList(); 我不会将它转换回逗 ...
-
我会先创建一个类来保存列表中的每个项目。 public class Creature { public string Name { get; set; } public string Species { get; set; } public int Count { get; set; } public Creature(string name, string species, int count) { this.Name = name; ...
-
您不明确,因为我们不知道您是否以元素存在开始,或者您只将逗号分隔列表作为纯文本,并且元素由jQuery添加。 如果你在jQuery之前有元素 使用jQuery,您可以使用:even选择器 。 $('td.wide span:even").addClass("alt"); 如果在jQuery之前没有元素 (另) var list = $('td.wide').html(); var listAsArray = list.split(','); var newL ...
-
MYSQL JOIN条件检查以逗号分隔列表的整数(MYSQL JOIN Conditional to check integer against comma delimited list)[2023-01-13]
您拥有的是一对多关系的完美示例,其中您有一个订单和几个附加的项目。 你应该有一个类似的链接表 order_product - 它在orderid和productid之间建立连接,你也可以为两者之间的关系放置特定数据(比如添加项目时,数量等) 然后使用此表进行连接,并且到处都有相同的字段类型。 简单的例子: select /* list of products */ from order o, order_product op, product p where o. ... -
以逗号分隔列表以编程方式设置列表框中选定的项目(Programmatically set listbox selected items from comma separated list)[2021-11-10]
由于您已经在ListBox有项目,并且您只想选择string.Split操作返回的string.Split然后使用ListBox.SetSelected方法,如: var valueArray = valueList.Split(','); for (int i = 0; i < listBox.Items.Count; i++) { if (valueArray.Contains(listBox.Items[i].ToString())) { listBox.SetSele ... -
怎么样: <%=String.Join( ",", Model.Select( person=> Html .ActionLink
( c => c.Edit(person.PersonID), Html.Encode(person.Name) ) ) .ToArray() )%> (另) ... -
使用一点XML,您可以动态地收集和“字符串化”您的值 Declare @tableRows table (RowCode varchar(50), RowOrd int, RowText varchar(50)) Insert Into @tableRows values ('RowA',1,'Row A'), ('RowB',2,'Row B') Declare @listStr VARCHAR(MAX) = '' Select @listStr = @listStr + C.String + ...