首页 \ 问答 \ Java泛型是否允许在诸如short之类的原语数组中节省内存?(Do Java generics allow for memory savings in arrays of primitives such as short?)

Java泛型是否允许在诸如short之类的原语数组中节省内存?(Do Java generics allow for memory savings in arrays of primitives such as short?)

我做了一些谷歌搜索,但我一直无法找到这个问题的决定性答案。 为了澄清,请考虑这样的类:

public class MyContainer<T> {
    private T[] _store;
    private int _size;
    ...
}

是否有可能通过使用shortint类型的数组来实现内存节省,尽管事实上必须使用ShortInteger等原始包装类声明带有MyContainer引用的变量,并且MyContainer实例必须用这些相同的包装类创建?

在我的搜索中,我发现Java编译器将类型擦除应用于泛型,但我不太确定我现在可以假设Java没有对通用类型数组进行某种优化。

有没有人有证据支持或反对这个? 提前致谢。


I've done a bit of Googling, but I've been unable to find a decisive answer to this question. For clarification, consider a class like this:

public class MyContainer<T> {
    private T[] _store;
    private int _size;
    ...
}

Is it possible to achieve the memory savings one would get by using an array of type short vs. int, despite the fact that a variable with a reference to MyContainer must be declared with primitive wrapper classes like Short and Integer, and instances of MyContainer must be created with those same wrapper classes?

In my searches I found that the Java compiler applies type erasure to generics, but I'm not so sure that I can now assume Java does not have some sort of optimization for generically-typed arrays.

Does anyone have evidence for or against this? Thanks in advance.


原文:https://stackoverflow.com/questions/18907419
更新时间:2024-01-13 16:01

最满意答案

这个问题很古老,但仍然试图回答我的最好可能会帮助某人

虽然所有的对象和属性值都是正确的,但脚本在您的情况下会间歇性地失败原因是要加载的对象的时间变化。 您必须通过使用WaitForPageloaded()来增加两者之间的同步时间。 方法


This question is pretty old, but still try to answer my best might help someone

Script intermittently failing in your case though all the objects and property values are correct Reason is time variation of objects to load. You have to increase synctime inbetween bojects by using WaitForPageloaded(); method

相关问答

更多
  • 这个问题很古老,但仍然试图回答我的最好可能会帮助某人 虽然所有的对象和属性值都是正确的,但脚本在您的情况下会间歇性地失败原因是要加载的对象的时间变化。 您必须通过使用WaitForPageloaded()来增加两者之间的同步时间。 方法 This question is pretty old, but still try to answer my best might help someone Script intermittently failing in your case though all the ...
  • 这里有一篇关于iPhone自动化用户界面测试的文章,您可能会发现有用的。 这是一个小丑,但它可能会完成某些任务的工作。 请注意,我还没有尝试过。 Here's an article about automated user interface testing for the iPhone that you may find helpful. It's a little kludgy but it probably gets the job done for certain tasks. Note that ...
  • 我推荐WebTest ; 它功能齐全,使用方便。 这是一个完整的工作示例,演示了一个简单的测试: from bottle import Bottle, response from webtest import TestApp # the real webapp app = Bottle() @app.route('/rest/') def root(name): '''Simple example to demonstrate how to test Bottle routes'' ...
  • 我使用了三种,具体取决于具体情况:SimpleTest,PHPUnit和Zend_Test(它实际上只是PHPUnit与Zend Framework一起使用的包装器)。 其中,SimpleTest真的很容易。 但是,PHPUnit提供了很多功能和灵活性。 There are three that I use, depending on the situation: SimpleTest, PHPUnit, and Zend_Test (which is really just a wrapper for P ...
  • 在您的Gemfile上需要ruby-debug。 如果在1.8: gem 'ruby-debug' 如果在1.9: gem 'ruby-debug19', :require => 'ruby-debug' 请注意,如果你在1.9.3上需要一些调整 。 最后,在你想调试的地方放一个debugger语句,然后运行你的测试。 它应该弹出一个控制台。 正如Amadan所说,我还建议看看pry。 Require ruby-debug on your Gemfile. If on 1.8: gem 'ruby-debu ...
  • 维基百科 : [单元测试]的实现可以从非常手动(铅笔和纸)到作为构建自动化的一部分正式化。 我不认为你会赢得你的赌注。 :( From Wikipedia: [A unit test's] implementation can vary from being very manual (pencil and paper) to being formalized as part of build automation. I don't think you will win your bet. :(
  • 没有办法强迫Yodlee Test Bank每次都返回相同的CAPTCHA。 由于Yodlee试图让测试银行提供更多真实的银行体验,这就是为什么它会返回新的CAPTCHA。 No there is no way to force Yodlee Test Bank to return same CAPTCHA every time. As Yodlee tries to keep the Test banks to provide more real bank experience this is why i ...
  • 有关测试自动化的SO有几个主题: 哪个更适合网络测试? 记录播放自动化或编码? 用户界面测试 GUI的自动测试 我从未使用过Quick Test Pro,但我参与了几个使用不同自动化测试工具的项目; Silk Test,Rational Robot,WinRunner。 这些努力中最成功的是使用Rational Robot和RRAFS框架将应用程序更改与测试脚本隔离开来。 我们还使用STAF框架来自动化和管理我们的测试基础架构。 自动化测试是测试应用程序方面的一种很好的技术,但它并不能取代人类测试人员。 像 ...
  • 一般来说,单元测试是针对开发人员的。 当开发人员编写代码时,应确保它在最常见的情况下工作。 在.NET中,我们使用NUnit,MSUnit等来测试代码和逻辑。 自动化测试通常发生在连续集成环境中测试的单元之上。 自动化测试通常由QA通过使用Selenium,Protractor,WinRunner等工具完成。 希望这可以帮助。 In general unit testing is meant for the developers. When a developer writes the code he sh ...
  • Selenium - http://seleniumhq.org/ Selenium - http://seleniumhq.org/

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。