是否可以获得通用参数的类型?
一个例子:
public final class Voodoo {
public static void chill(List<?> aListWithTypeSpiderMan) {
// Here I'd like to get the Class-Object 'SpiderMan'
Class typeOfTheList = ???;
}
public static void main(String... args) {
chill(new ArrayList<SpiderMan>());
}
}
Run Code Online (Sandbox Code Playgroud) 我有这样一张桌子:
+-----+-----+-------+
| id | fk | value |
+-----+-----+-------+
| 0 | 1 | peter |
| 1 | 1 | josh |
| 3 | 2 | marc |
| ... | ... | ... |
Run Code Online (Sandbox Code Playgroud)
我现在想要获得具有多个值的所有条目.预期结果将是:
+-----+-------+
| fk | count |
+-----+-------+
| 1 | 2 |
| ... | ... |
Run Code Online (Sandbox Code Playgroud)
我试图像这样实现:
select fk, count(value) from table where count(value) > 1;
Run Code Online (Sandbox Code Playgroud)
但甲骨文并不喜欢它.
所以我试过这个......
select * from (
select fk, count(value) as cnt from table
) …
Run Code Online (Sandbox Code Playgroud) 你自己已经看过很多次了,我敢肯定:
public SomeObject findSomeObject(Arguments args) {
SomeObject so = queryFirstSource(args); // the most likely source first, hopefully
if (so != null) return so;
so = querySecondSource(args); // a source less likely than the first, hopefully
if (so != null) return so;
so = queryThirdSource(args); // a source less likely than the previous, hopefully
if (so != null) return so;
// and so on
}
Run Code Online (Sandbox Code Playgroud)
我们有不同的来源,我们搜索的对象可能是.作为一个更生动的例子,我们可以想象我们首先检查用户标识是否在特权用户列表中.如果不是,我们检查用户标识是否在允许的用户列表中.否则我们返回null.(这不是最好的例子,但我希望它足够生动.)
Guava为我们提供了一些可以美化上述代码的帮助:
public SomeObject findSomeObject(Arguments args) {
// if there are only two objects
return …
Run Code Online (Sandbox Code Playgroud) 我想知道是否有更短/更简单的方法:
有两个限制:没有库,没有循环
#include <string>
#include <iterator>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <deque>
void list_string_elements(std::string s) {
using namespace std;
istringstream iss (s);
deque<string> v;
copy(istream_iterator<string>(iss), istream_iterator<string>(), front_inserter(v));
copy(v.begin(),v.end(),ostream_iterator<string>(cout,"\n"));
}
Run Code Online (Sandbox Code Playgroud) 我的问题:
我有一个DataSet
多个DataTables
.所有这些DataTables
都有一个DataColumn
名为"ID"用DataType
的System.Guid
.
这样一个表的一个简短例子:
+--------------------+
| User |
+--------------------+
| *Id as System.Guid |
| Username as String |
| /* more columns */ |
+--------------------+
Run Code Online (Sandbox Code Playgroud)
我把它分配DataTable
给了DataGridView
.在DataGridView
被配置为允许条目的创建,编辑和删除.
当用户现在创建新条目并保存它时,会出现"Id"未设置的异常.
我的问题:
如何自动生成System.Guid
新条目的新内容?
我目前的想法:
dataSet.dataTable.Columns['Id'].DefaulValue
.(像这样的东西<DBNull>
)dataSet.dataTable
侦听新行时使用类似触发器的东西.它必须在行验证之前执行dataGridView
.我尝试过的:
DataGridView
:RowsAdded
,UserAddedRow
,RowValidating
,DefaultValuesNeeded
如果有人能为我提供工作解决方案或提示,那将是非常棒的!
〜克里斯
为什么不是Map<String,List<SomeBean>>
施法者Map<String,List<?>>
?
我现在正在做的是:
Map<String, List<SomeBean>> fromMap = new LinkedHashMap<String, List<SomeBean>>();
/* filling in data to fromMap here */
Map<String,List<?>> toMap = new LinkedHashMap<String, List<?>>();
for (String key : fromMap.keySet()) {
toMap.put(key, fromMap.get(key));
}
Run Code Online (Sandbox Code Playgroud)
在我看来,应该有一种解决这种手动转换的方法,但我无法弄清楚如何.有任何想法吗?