如何获取具有多个generics类型的类型以匹配类型参数?

例如,假设我想要一个Map<Class, List> ,那么我可以放入一个类并获取该类型的列表 – 是否有什么东西可以替换问号以使其发生?

Google App Engine Jersey错误格式json

我正在使用带有Jersey和JAX-RS的Google App Engine JAVA开发REST API。 我希望能够以JSON格式向用户发送自定义错误,因为我正在使用javax.ws.rs.ext.ExceptionMapper 当我在本地计算机上使用Jetty运行应用程序时,一切正常,但是当我部署到Google时,我得到了默认的HTML 404页面 这是资源代码: @GET @Produces(MediaType.APPLICATION_JSON) @Path(“{id}”) public Customer getCustomer(@PathParam(“id”) String id) { Customer customer = getCustomer(id); if(customer == null) throw new NotFoundException(“Customer not found”); return customer; } exception映射器: @Provider public class NotFoundExceptionMapper implements ExceptionMapper { @Override public Response toResponse(NotFoundException e) { ErrorMessage errorMessage = new ErrorMessage(); errorMessage.setErrrorMessage(e.getMessage()); errorMessage.setResponseCode(404); return […]

如何在Java中打印字符串数组的偶数和奇数位置字符?

题 给定长度为N的字符串S,其从0到N-1索引,在单行上打印它的偶数索引和奇数索引字符作为2个空格分隔的字符串。 假设输入从索引位置0开始(被认为是偶数) 输入 第一行包含一个整数T(测试用例的数量)。 T个后续行的每一行i包含一个String,S。 产量 对于每个字符串S,打印它的偶数索引字符,后跟空格,后跟奇数索引字符。 样本输入 2 黑客 秩 样本输出 Hce akr Rn ak 我写的守则 public static void main(String[] args) { Scanner scan = new Scanner(System.in); int T = scan.nextInt(); scan.nextLine(); for(int i=0 ; i<T ; i++) { String myString = scan.nextLine(); int evn = 0, odd = 0, len = myString.length(); […]

从二叉树中删除叶子没有正确表示

我一直致力于从头开始创建二叉树,而不是使用内置库。 我正在开发一个名为“pruneLeaves”的函数。 工作是删除树的所有叶子; 没有孩子的节点。 当我使用断点逐步执行该函数时,它似乎正在删除叶子,甚至打印出它确实正在删除正确的节点。 但是,当我之后在主函数中显示树时,节点仍然存在! 我已经试了好几个小时来解决这个问题,我在俯瞰什么?! 节目输出: Num nodes = 9 Pruning. 12 Leaf removed 9 Leaf removed 4 Leaf removed Tree after pruning.. 3 4 5 6 7 8 9 11 12 // Recursive helper. Accepts BinaryNode as a parameter private BinaryNode pruneLeaves(BinaryNode t) { // If we have no left child AND […]

Neo4j SPARQL-plugin REST用法

我试图通过使用REST API在我的neo4j数据库上运行SPARQL查询。 为了获得SPARQL端点,我安装了Noe4j SPARQL插件( https://github.com/neo4j-contrib/sparql-plugin )。 我的系统现在公开了这些sparql-endpoints: http://localhost:7474/db/data/ext/SPARQLPlugin/graphdb/insert_quad http://localhost:7474/db/data/ext/SPARQLPlugin/graphdb/execute_sparql 我试图使用sencond执行查询。 HTTP POST请求应该与http://neo4j-contrib.github.io/sparql-plugin/中的 “示例2”类似,但查询稍微容易一些。 这是源代码: private static final String ENDPOINT = “http://localhost:7474/db/data/ext/SPARQLPlugin/graphdb/execute_sparql”; private static String query = “SELECT ?x WHERE {?x ?y ?z} LIMIT 5”; public static void main(String[] args) { try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(ENDPOINT); // Request parameters […]

Timemillisecond to hh:mm:java中的ss格式

在我的代码中,我生成的时间戳值为长毫秒。我想将其转换为HH:mm:ss(600000到00:10:00),我想要差异hh:mm:ss格式 String strstart = “8:30:00”; String strend = “8:40:00”; SimpleDateFormat sdf1 = new SimpleDateFormat(“hh:mm:ss”); try { Date date1 = sdf1.parse(strstart); Date date2 = sdf1.parse(strend); long durationInMillis = date2.getTime() – date1.getTime(); System.out.println(“durationInMillis—->” + durationInMillis); } catch (ParseException e) { // TODO Auto-generated catch block e.printStackTrace(); } 我使用波纹管代码,输出为0:10:0但我希望输出像00:10:00 int seconds = (int) (durationInMillis / 1000) % 60 […]

将声音文件转换为具有特定比特率的wav并剪切文件的特定部分

我有一些声音文件(基本上是mp3,但它可以是任何比特率)。 我需要方法将输入文件的指定部分(不超过40秒)提取到8位单声道wav输出。 我很感激选择java库的任何帮助或建议。

为什么将org.slf4j.api添加到依赖项会导致在注册表错误中找不到应用程序?

如果RCP行为中有任何逻辑,我绝对不明白。 我正在尝试记录内部视图。 我的应用程序运行正常,直到我添加了对org.slf4j.api依赖 代码中没有其他任何内容被更改。 但这种依赖性变化导致了这种荒谬的错误 !ENTRY org.eclipse.osgi 4 0 2014-01-10 17:25:08.072 !MESSAGE Application error !STACK 1 java.lang.RuntimeException: Application “Try_EclipseRCPView_03.application” could not be found in the registry. The applications available are: org.eclipse.e4.ui.workbench.swt.E4Application, org.eclipse.e4.ui.workbench.swt.GenTopic, org.eclipse.equinox.app.error, org.eclipse.ant.core.antRunner. at org.eclipse.equinox.internal.app.EclipseAppContainer.startDefaultApp(EclipseAppContainer.java:248) at org.eclipse.equinox.internal.app.MainApplicationLauncher.run(MainApplicationLauncher.java:29) at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLaunche … 如果我删除依赖项,错误消失。 为什么????? UPDATE 最后Eclipse崩溃并删除了我的所有文件(消灭了,这不是一个笑话)。 我认为它甚至不可能。 小心Eclipse平台是由白痴写的。 我很伤心。

多次调用paintComponent()

我有这两个类: public class Pencil extends JComponent implements MouseListener, MouseMotionListener{ Plansa plansa; Graphics g; public Pencil(Plansa newCanvas){ this.plansa = newCanvas; this.plansa.setFlagShape(false); } @Override public void mouseDragged(MouseEvent arg0) { plansa.setMouseDragged(arg0); this.plansa.setFlagShape(false); plansa.paintComponent(plansa.getGraphics()); } @Override public void mouseClicked(MouseEvent e) { } @Override public void mousePressed(MouseEvent arg0) { plansa.setMousePressed(arg0); } @Override public void mouseReleased(MouseEvent arg0) { // TODO Auto-generated […]

ANDROID:在一个textView中的多对字符串之间导航

闪存卡应用程序 我有多个静态字符串存储在strings.xml上,我想使用prev_Clicked / next_Clicked按钮在它们之间导航。 我还希望能够在应用程序运行时存储问题和答案的字符串,并通过prev / next按钮访问这些字符串 感谢您的时间,请关注我的代码: 的.java public class MainActivity extends splashActivity { Button closeButton, addButton, prevButton, nextButton; TextView QAText, answerText; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_flashcard); QAText = (TextView) findViewById(R.id.fcfront_textView); answerText = (TextView) findViewById(R.id.fcfront_textView); //not used anywhere atm QAText.setOnClickListener(new View.OnClickListener() { //function to toggle between Q/A public void onClick(View v) […]