为什么SomeClass 不等同于Javagenerics类型中的SomeClass ?

我注意到了Collections.sort的具体说明: public static void sort(List list, Comparator c) 为什么这里需要“ ? super ”? 如果ClassB扩展了ClassA ,那么我们不能保证Comparator能够比较两个ClassB对象,而没有“ ? super ”部分吗? 换句话说,鉴于此代码: List list = . . . ; Comparator comp = . . . ; Collections.sort(list, comp); 为什么编译器不够聪明,即使没有为Collections.sort()的声明指定“ ? super ”,也知道这没关系?

Linux JVM实际上是否实现了线程优先级?

写了一个快速的Java proggy以产生每个优先级的10个线程并计算pi(4 * atan(1)方法),每个BigDecimals 500,000次,加入每个线程并报告run方法的运行时间。 是的,可能不是最好的例子,但保持基本。 我知道Bug4813310 在C中做起来并非易事,但是我们可以假设在Linux JVM上永远不会设置原生优先级吗? $uname -r && grep bogomips /proc/cpuinfo 2.4.33.3 bogomips : 4312.26 $java -version 2>&1 |head -1 Java version “1.6.0_01” $javac T.java && java -Xmx32m -XX:+UseThreadPriorities T 1:3112 2:2636 3:2662 4:3118 5:2870 6:3319 7:3412 8:3304 9:3299 10:3069 看起来没有人会期待的偏差! 那是在一台小型虚拟Linux机器上。 也许只是Sun的? 我们将尝试IBM J9 VM: 1:4091 2:4142 3:3957 4:3905 5:3984 […]

jsp是如何工作的?

我想知道JSP有没有被编译? 我之所以要问的原因是因为每当我在Web服务器上部署我的Java EE应用程序时,我只会在WEB-INF文件夹中看到那些servlet和beans类文件,因为它们是编译的,但不是那个JSP,所以它是如何工作的什么是正常请求/响应周期的逻辑流程和大图。

用于Java的线性编程工具/库

我想建立一个大的线性编程模型来解决一个有趣的问题。 我最熟悉Java。 有哪些工具/库?

generics和Class.forName

我想使用其名称创建指定类的实例。 我的代码如下所示。 我收到编译器警告。 我这样做是对的吗? 甚至可以使用类的名称并获取该类型的实例,因为我认为编译器没有任何方法知道该类型应该是什么? public static T create(final String className) { try { final Class clazz = Class.forName(className); //WARNING: Type safety: Unchecked cast from capture#2-of ? to T return (T) create(clazz); } catch (ClassNotFoundException e) { e.printStackTrace(); } } public static T create(final Class classToCreate) { final Constructor constructor; try { constructor = classToCreate.getDeclaredConstructor(); […]

如何从GWT调用RESTFUL服务?

我正在使用GWT作为Web开发框架。 我需要从我的GWT客户端代码访问一些REST服务。 此外,我需要解析JSON(或XML),这是这些服务的响应格式。 哪个是解决这个问题的最佳方法? 提前致谢。

访问.jar外的属性文件?

我有一个.jar文件,我正在放在一起。 我想创建一个非常简单的.properties文件,其中包含用户名和其他内容等可配置的东西,这样他们就可以手工编辑而不是必须包含GUI编辑器。 我想做的是能够按以下顺序搜索: 指定的属性文件( args[0] ) 当前目录中的MyApp.properties(调用Java的目录) 用户目录中的MyApp.properties( user.home系统属性?) 存储应用程序.jar的目录中的MyApp.properties 我知道如何访问#1和#3(我认为),但是如何在运行时#2和#4确定?

UserTransaction如何传播?

我有一个带有bean管理事务的无状态bean,以及一个这样的方法: @Stateless @TransactionManagement(TransactionManagementType.BEAN) public class … { @Resource private UserTransaction ut; @EJB private OtherStatelessBeanLocal other; public void invokeSomeMethods() ut.begin(); … // invoke other bean’s methods here. other.method(); … ut.commit(); } } 那么UserTransaction如何传播到OtherStatelessBeanLocal bean?

如何从另一个面板更改卡布局面板?

我用Google搜索了很多,没有找到解决方案。 我想应该有java大师来帮助我… 这是我的初始化方法: private void initialize() { this.setSize(750, 480); this.setContentPane(getJContentPane()); this.setTitle(“Registration”); JPanel topPane = new TopPane(); this.getContentPane().add(topPane,BorderLayout.PAGE_START); cards=new JPanel(new CardLayout()); cards.add(step0(),”step0″); cards.add(step1(),”step1″); cards.add(step2(),”step2″); this.getContentPane().add(cards,BorderLayout.CENTER); } public JPanel step2(){ EnumMap template = new EnumMap(DPFPFingerIndex.class); JPanel enrol = new Enrollment(template,2); return enrol; } public JPanel step0(){ JPanel userAgree = new UserAgreement(); return userAgree; } public JPanel step1(){ […]

在Set中存储数组并避免重复

HashSet boog = new HashSet(); boog.add(new String[]{“a”, “b”, “c”}); boog.add(new String[]{“a”, “b”, “c”}); boog.add(new String[]{“a”, “b”, “d”}); 结果是 [a, b, c] [a, b, d] [a, b, c] 其中[a,b,c]重复,因此散列函数不能按预期工作。 我将如何重写String数组的Hash方法。 或者就此而言,通用数组? 有没有更好的方法来完成我想要做的事情?