Getting Type instance of implemented interface with type parameters applied

Given a Type instance (which may be a Class or ParameterizedType), I need to get the specific Type of an interface implemented by the class. Without generics this is easy, call getInterfaces() on a Class instance and you're done. However, I need this to work even when the implemented interface has its own type parameters that may or may not depend on the type parameters of the original clas

获取应用了类型参数的已实现接口的Type实例

给定一个Type实例(可能是一个Class或ParameterizedType),我需要获得该类实现的特定类型的接口。 如果没有泛型,这很容易,可以在Class实例上调用getInterfaces()并完成。 然而,即使当实现的接口具有自己的类型参数时,我也需要它来工作,这些类型参数可能取决于原始类本身的类型参数,也可能不取决于类型参数。 一些例子,当给定一个类时,函数应该返回Iterable <Integer> class Foo implements Iterable<Int

Determine if a Class implements a interface in Java

I have a Class object. I want to determine if the type that the Class object represents implements a specific interface. I was wondering how this could be achieved? I have the following code. Basically what it does is gets an array of all the classes in a specified package. I then want to go through the array and add the Class objects that implement an interface to my map. Problem is the i

确定一个类是否在Java中实现一个接口

我有一个Class对象。 我想确定Class对象表示的类型是否实现了特定的接口。 我想知道如何实现这一目标? 我有以下代码。 基本上它所做的是获取指定包中所有类的数组。 然后我想通过数组并将实现接口的Class对象添加到我的地图。 问题是isInstance()将一个对象作为参数。 我无法实例化一个接口。 所以我对此感到不知所措。 有任何想法吗? Class[] classes = ClassUtils.getClasses(handlersPackage); for(Class clazz :

can't cast to implemented interface

i'm very confused... I have a class which directly implements an interface: public class Device implements AutocompleteResult {...} Here is proof that I'm looking at the right variables: Object match = ...; log.debug(match.getClass()); // Outputs 'Device' log.debug(match.getClass().getInterfaces()[0]); // Outputs 'AutocompleteResult' Yet when I try to cast an instance of the class t

无法投射到实现的界面

我很困惑... 我有一个直接实现接口的类: public class Device implements AutocompleteResult {...} 这是证明我正在查看正确的变量: Object match = ...; log.debug(match.getClass()); // Outputs 'Device' log.debug(match.getClass().getInterfaces()[0]); // Outputs 'AutocompleteResult' 然而,当我尝试将类的一个实例转换为接口时: AutocompleteResult result = (AutocompleteResult) match; 我得到一个ClassC

algorithm/theory for GPS position jitter removal

I'm trying to write a GPS tracking (akin to a jogging app) on android and the issue of GPS location jitter has reared it's ugly head. When accuracy is FINE and accuracy is within 5 meters, the position is jittering 1-n meters per second. How do you determine or filter out this jitter from legitimate movement? Sporypal etc apps clearly have some way they are filtering out this noise.

GPS位置抖动消除的算法/理论

我正在尝试在Android上编写一个GPS跟踪(类似于慢跑应用),并且GPS位置抖动问题已经引发了它的丑陋头脑。 当精度为FINE且精度在5米以内时,位置抖动为每秒1米。 你如何确定或滤除合法运动中的抖动? Sporypal等应用显然有一些方法可以滤除这种噪音。 有什么想法吗? 你可以通过低通滤波器来运行位置吗? 订单的东西 x(n) = (1-K)*x(n-1) + K*S(n) 哪里 S是你的噪声样本,x是低通滤波样本。 K是一个介于0和1之间

Real World Example of the Strategy Pattern

I've been reading about the OCP principal and how to use the strategy pattern to accomplish this. I was going to try and explain this to a couple of people, but the only example I can think of is using different validation classes based on what status an "order" is. I've read a couple of articles online, but these don't usually describe a real like reason to use the stra

战略模式的实例

我一直在阅读关于OCP负责人以及如何使用战略模式来实现这一目标。 我将尝试向几个人解释这一点,但我能想到的唯一例子是根据“订单”的状态使用不同的验证类。 我已经在线阅读了几篇文章,但这些文章通常不会描述使用策略的真实原因,例如生成报告/帐单/验证等。 在你认为战略模式很普遍的情况下,是否有真实世界的例子? 那这个呢: 你必须加密一个文件。 对于小文件,您可以使用“内存”策略,即完整文件被读取并保存

Why should the interface for a Java class be preferred?

PMD would report a violation for: ArrayList<Object> list = new ArrayList<Object>(); The violation was "Avoid using implementation types like 'ArrayList'; use the interface instead". The following line would correct the violation: List<Object> list = new ArrayList<Object>(); Why should the latter with List be used instead of ArrayList ? Using inter

为什么要选择Java类的接口?

PMD将报告违规行为: ArrayList<Object> list = new ArrayList<Object>(); 违规是“避免使用像'ArrayList'这样的实现类型;使用接口来代替”。 以下行将纠正违规行为: List<Object> list = new ArrayList<Object>(); 为什么要用List代替ArrayList ? 在具体类型上使用接口是良好封装和松散耦合代码的关键。 在编写自己的API时遵循这种做法甚至是一个好主意。 如果你这么做了,你会发现

receiving custom XML messages

I've spend some time to add smack.providers in the android device, which is picked up by my application just fine. I've added the default iqProviders and extensionProviders, but I've also added my custom extensionProvider, which is the following: <extensionProvider> <elementName>players</elementName> <namespace>boxer:players</namespace> <classN

接收定制的XML消息

我花了一些时间在Android设备中添加smack.providers,这是由我的应用程序拾取的很好。 我已经添加了默认的iqProviders和extensionProviders,但我还添加了我的自定义extensionProvider,它是以下内容: <extensionProvider> <elementName>players</elementName> <namespace>boxer:players</namespace> <className>company.games.boxer.PlayerListProvider</className> </ex

Java: Method does not return. (XComponent.dispose

I use the OpenOffice API from my Java Program to handle Documents for me. Sometimes (once every 100k or so calls) the dispose method of a Document does not return, the CPU load stays at 100% but nothing seems to happen. How should I act / code correctly in this situation? My current approach is to wait for the dispose to succeed for two seconds. If it does not I try to terminate OpenOffice

Java:方法不返回。 (XComponent.dispose

我使用Java程序中的OpenOffice API来为我处理文档。 有时(每100k左右调用一次)Document的处理方法不会返回,CPU负载保持100%,但似乎没有任何事情发生。 在这种情况下,我应该如何行动/正确编码? 我目前的做法是等待处置成功两秒钟。 如果没有,我尝试通过适当的API终止OpenOffice。 如果失败了(就像我所期望的那样),那么我会通过致电来杀死soffice进程 XDesktop xDesk = (...) // achive desktop xDesk.terminate

Ivy: Resolving and Publishing JARs Locally

We have been using Ivy for a few months and have our own hosted "Ivy Repo" on a web server here in the office. All of our projects are configured to go to this repo to resolve dependencies. We have several "commons" type JARs that are used by many of our projects. Because of this, and because we only have 1 repo, we're finding a lot of ugly overhead coming from the fol

常春藤:本地解析和发布JAR

我们已经使用Ivy几个月,并在办公室的网络服务器上拥有自己的“常春藤回购”。 我们所有的项目都配置为转到此回购以解决依赖关系。 我们有许多我们许多项目使用的“commons”类型的JAR。 正因为如此,并且由于我们只有1个回购,我们发现来自以下场景的许多丑陋的开销: 开发人员有权向Project 1添加一个功能(取决于Common jar) 在开发Project 1的过程中,开发人员意识到他/她需要对Common jar进行更改 常见的jar更改已经

Recommendations on a free library to be used for zipping files

I need to zip and password-protect a file. Is there a good (free) library for this? This needs to be opened by a third party, so the password protection needs to work with standard tools. After much searching, I've found three approaches: A freely available set of source code, suitable for a single file zip. However, there is no license. Usage is AesZipOutputStream.zipAndEcrypt(...).

有关用于压缩文件的免费库的建议

我需要压缩并密码保护文件。 有没有一个好的(免费)图书馆? 这需要由第三方开放,因此密码保护需要使用标准工具。 经过多次搜索,我发现了三种方法: 一套免费的源代码,适用于单个文件zip。 但是,没有许可证。 用法是AesZipOutputStream.zipAndEcrypt(...)。 http://merkert.de/de/info/zipaes/src.zip(https://forums.oracle.com/forums/thread.jspa?threadID=1526137) 更新:此代码现在获得Apache许可,并