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
最满意答案
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.
- 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.
- Time - Cost. Really it might take time to get over, but still I don't know how much until I redesign it.
- Admin Expirience - might be wrong about this since with Framework programmer can create admin for only what customer really needs.
- 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.
相关问答
更多-
通过composer安装yii2问题[2022-04-19]
语法:“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主题(How can I customize yii2 theme)[2022-12-25]
嗨,你必须做如下事情在yii2主题像yii1一样简单: - 首先打开web.php进入yii2应用程序的config目录, 然后在组件数组传递视图数组中,如: 'view' => [ 'theme' => [ 'pathMap' => [ '@app/views' => [ '@webroot/themes/demo/views', ... -
Yii2只运行特定的迁移(Yii2 run only specific migration)[2022-06-18]
已应用“运行migrate/history到列表迁移”。 ./yii migrate/history 复制您想要稍后返回的迁移名称(假设它是'm160101_185401_initial_migration')。 把它保存到某个地方因为你以后会需要它 将迁移历史记录标记在您需要运行的历史记录之前 ./yii migrate/mark m170101_185401_create_news_table 运行一次迁移 ./yii migrate 1 重置迁移历史记录 ./yii migrate/mark ... -
在Yii2中集成paytm(Integrate paytm in Yii2)[2022-06-03]
我在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 -
将Yii2从Apache迁移到Nginx - 在后端应用程序上失败(Migrating Yii2 from Apache to Nginx - failed on backend app)[2023-04-20]
通过添加下面的配置自己修复它 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(Migrating from Joomla to Yii2)[2022-08-11]
Joomla是一个内容管理应用程序,而Yii2是一个框架,一个很棒的框架。 如果代码的定制级别非常高,则使用应用程序或CMS标准的好处变得非常少,并且使用框架的优势很多。 通常,框架,尤其是Yii用于创建常见应用程序的特殊版本,在这些之间,CMS是更好地考虑的模块之一。 数据模型定义相当清晰,大部分工作都集中在定制功能上。 As I asked for my project, I later found answer by myself. This project that is explained wou ... -
Yii2 Mongodb迁移(Yii2 Mongodb Migration)[2022-04-22]
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`');
-
Yii2和Reportico(Yii2 and Reportico)[2023-07-16]
Reportico只使用mysql和postgres中的标准sql ...所以连接只是使用标准的sql连接... 我建议你做的是在这里转到reportico sourceforge网站并获得最新的4.5附带教程..你将学习在这里使用连接....在这里得到它.. https://sourceforge.net/projects/reportico/files/?source=navbar 提取到一个Web文件夹并将浏览器指向它..然后您可以使用最新的文档来了解reportico ..您所做的一切将适用于yii ...