首页 \ 问答 \ Java通用算术(Java generic arithmetic)

Java通用算术(Java generic arithmetic)

我正在尝试创建一些Java类,它们应该使用float或double数字(出于模拟目的,我需要支持两者)。 这些类需要做一些基本的算术,还需要使用三角函数(sin,cos,atan2)。

我试图做一个通用的方法。 由于Java不允许泛型中的原始类型和MyClass<T extends Number>确实允许Double和Float,但是基本算法不可能,我在Double和Float周围构建一个包装类。 但是,只要我需要在其中一个泛型类中实例化一个值,这种方法就会失败。

是否有任何干净的方法来支持float和double,而不重复每种类型的所有代码?


I'm trying to create some Java classes, that should work with either float or double numbers (for simulation purposes I am required to support both). The classes need to do some basic arithmetic and also require use of trigonometric functions (sin, cos, atan2).

I tried to do a generic approach. As Java does not allow primitive types in generics and MyClass<T extends Number> does indeed allow Double and Float, but makes basic arithmetic impossible, I build a wrapper class around Double and Float. But this approach fails, as soon as I need to instantiate a value in one of the generic classes.

Is there any clean way to support both float and double, without duplicating all the code for each type?


原文:https://stackoverflow.com/questions/13911188
更新时间:2023-06-01 18:06

最满意答案

Joomla是一个内容管理应用程序,而Yii2是一个框架,一个很棒的框架。 如果代码的定制级别非常高,则使用应用程序或CMS标准的好处变得非常少,并且使用框架的优势很多。

通常,框架,尤其是Yii用于创建常见应用程序的特殊版本,在这些之间,CMS是更好地考虑的模块之一。 数据模型定义相当清晰,大部分工作都集中在定制功能上。


As I asked for my project, I later found answer by myself. This project that is explained would be easily defined as Web Application and not only Web site, better relation between these two is already answered here:

What's the difference between a web site and a web application?

https://en.wikipedia.org/wiki/Web_application

Declaration "If some site is Web application" is mostly based on opinion, while my explanation of project pushes it to far end to Web Application. While Joomla is somewhere in the middle to support both with ease, yii2 is constructed as base for web applications.

So why is better to stick with Joomla.

  1. Articles - There is article system created as 'ready to use' which is good for static pages like blog or some similar stuff, which almost all web sites needs it.
  2. Time - Cost. Really it might take time to get over, but still I don't know how much until I redesign it.
  3. Admin Expirience - might be wrong about this since with Framework programmer can create admin for only what customer really needs.
  4. Click&Install - I'm really reconsidering to mark as advantage when comes to some big applications. Customers tend to install alot of components/modules/plugins that makes web app working every day worse and worse.

As scaisedge said in his answer there are few benefits of using Joomla versus Yii2 in such projects since level of customization of code is high and seems that any other development comes in favor of Yii2/any framework based on same idea. This can be applied to any other similar project.

相关问答

更多
  • 语法:“curl -sS https://getcomposer.org/installer | php中bin目录里的php可执行文件路径” 我这里的php可执行文件所在路径是/usr/local/php/bin/php 所以实际安装命令如下: curl -sS https://getcomposer.org/installer | /usr/local/php/bin/php 为方便日后使用将其移动到本地系统可执行文件目录 并重新命名为 composer(这样以后执行命令时就不用写composer.ph ...
  • 嗨,你必须做如下事情在yii2主题像yii1一样简单: - 首先打开web.php进入yii2应用程序的config目录, 然后在组件数组传递视图数组中,如: 'view' => [ 'theme' => [ 'pathMap' => [ '@app/views' => [ '@webroot/themes/demo/views', ...
  • 已应用“运行migrate/history到列表迁移”。 ./yii migrate/history 复制您想要稍后返回的迁移名称(假设它是'm160101_185401_initial_migration')。 把它保存到某个地方因为你以后会需要它 将迁移历史记录标记在您需要运行的历史记录之前 ./yii migrate/mark m170101_185401_create_news_table 运行一次迁移 ./yii migrate 1 重置迁移历史记录 ./yii migrate/mark ...
  • 我在github上创建了一个存储库。 请检查给定的链接 https://github.com/akhileshjha/yii2-paytm I have created a repository on github. Please check the given link https://github.com/akhileshjha/yii2-paytm
  • 通过添加下面的配置自己修复它 location ^~ /belakang { try_files $uri $uri/ /belakang/index.php$is_args$args; location ~ /\.(ht|svn|git) { deny all; } location ~ \.php$ { include fastcgi_params; fastcgi ...
  • 你有没有添加以下信息配置console.php 'controllerMap' => [ // Migrations for the specific project's module 'migrate-module' => [ 'class' => 'yii\console\controllers\MigrateController', 'migrationNamespaces' => ['app\module\migrations'], ...
  • Joomla是一个内容管理应用程序,而Yii2是一个框架,一个很棒的框架。 如果代码的定制级别非常高,则使用应用程序或CMS标准的好处变得非常少,并且使用框架的优势很多。 通常,框架,尤其是Yii用于创建常见应用程序的特殊版本,在这些之间,CMS是更好地考虑的模块之一。 数据模型定义相当清晰,大部分工作都集中在定制功能上。 As I asked for my project, I later found answer by myself. This project that is explained wou ...
  • MongoDB是noSql,因此每个文档的结构都可以不同。 在不知道文档结构的情况下,无法创建任何示例代码。 索引创建很简单,并且没有真正限制您的集合可以拥有多少索引。 每个文档都不需要具有那些索引键 - 值对。 在MongoDB中,键(列)没有固定类型。 您可以插入:x:1 x:longInt(1)x:“1”并且您有三个文档,每个文档都有不同类型的键x。 回答你的第二个问题...... /** * Builds and executes a SQL statement for creating ...
  • 好的,你可以试试这个: $this->addColumn('news', 'priority, 'integer AFTER `name` '); OK, can you try this: $this->addColumn('news', 'priority', 'integer AFTER `name`');
  • Reportico只使用mysql和postgres中的标准sql ...所以连接只是使用标准的sql连接... 我建议你做的是在这里转到reportico sourceforge网站并获得最新的4.5附带教程..你将学习在这里使用连接....在这里得到它.. https://sourceforge.net/projects/reportico/files/?source=navbar 提取到一个Web文件夹并将浏览器指向它..然后您可以使用最新的文档来了解reportico ..您所做的一切将适用于yii ...

相关文章

更多

最新问答

更多
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • linux的常用命令干什么用的
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • Java中的不可变类(Immutable class in Java)
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • 绑定属性设置器未被调用(Bound Property Setter not getting Called)
  • linux ubuntu14.04版没有那个文件或目录
  • 如何使用JSF EL表达式在param中迭代变量(How to iterate over variable in param using JSF EL expression)
  • 是否有可能在WPF中的一个单独的进程中隔离一些控件?(Is it possible to isolate some controls in a separate process in WPF?)
  • 使用Python 2.7的MSI安装的默认安装目录是什么?(What is the default installation directory with an MSI install of Python 2.7?)
  • 寻求多次出现的表达式(Seeking for more than one occurrence of an expression)
  • ckeditor config.protectedSource不适用于editor.insertHtml上的html元素属性(ckeditor config.protectedSource dont work for html element attributes on editor.insertHtml)
  • linux只知道文件名,不知道在哪个目录,怎么找到文件所在目录
  • Actionscript:检查字符串是否包含域或子域(Actionscript: check if string contains domain or subdomain)
  • 将CouchDB与AJAX一起使用是否安全?(Is it safe to use CouchDB with AJAX?)
  • 懒惰地初始化AutoMapper(Lazily initializing AutoMapper)
  • 使用hasclass为多个div与一个按钮问题(using hasclass for multiple divs with one button Problems)
  • Windows Phone 7:检查资源是否存在(Windows Phone 7: Check If Resource Exists)
  • 无法在新线程中从FREContext调用getActivity()?(Can't call getActivity() from FREContext in a new thread?)
  • 在Alpine上升级到postgres96(/ usr / bin / pg_dump:没有这样的文件或目录)(Upgrade to postgres96 on Alpine (/usr/bin/pg_dump: No such file or directory))
  • 如何按部门显示报告(How to display a report by Department wise)
  • Facebook墙贴在需要访问令牌密钥后无法正常工作(Facebook wall post not working after access token key required)
  • Javascript - 如何在不擦除输入的情况下更改标签的innerText(Javascript - how to change innerText of label while not wiping out the input)
  • WooCommerce / WordPress - 不显示具有特定标题的产品(WooCommerce/WordPress - Products with specific titles are not displayed)