假设我们有这个课程:
public abstract class A {
int x;
public int foo();
public int foo(int x);
}
Run Code Online (Sandbox Code Playgroud)
众所周知,A.class它具有明显的优势Class.forName("A"):如果A通过重构或混淆改变名称,它仍然可以工作.
但是,没有办法通过字段和方法获得这种优势.你有没有希望你能做到这一点:( 在下面的编辑中看到一个更好的建议语法!)
Field xField = A.x.field;
Method fooMethod = A.foo().method;
Method fooIntMethod = A.foo(int).method;
Run Code Online (Sandbox Code Playgroud)
而不是这个?
Field xField = A.getField("x");
Method fooMethod = A.getMethod("foo");
Method fooIntMethod = A.getMethod("foo", int.class);
Run Code Online (Sandbox Code Playgroud)
所以这是我的问题:有没有人知道这个功能是否已经计划或讨论过,或者Sun/Oracle是否出于某种原因特别决定反对它?
编辑:这个语法怎么样?它避免了人们提到的问题:
Field xField = A..x;
Method fooMethod = A..foo();
Method fooIntMethod = A..foo(int);
Run Code Online (Sandbox Code Playgroud)
用例示例
我最近创建了一个AbstractTableModel名为的类EasyTableModel,允许您定义自己的POJO行类型.它getValueAt(...)与setValueAt(...)等使用反射来获取/设置在POJO中的字段的值.
public class EasyTableModel<T> extends …Run Code Online (Sandbox Code Playgroud) 与使用node-inspector调试jasmine-node测试几乎相同的问题但是有没有人知道如何使用节点检查器和业力?
在维基百科上的文件I/O的RAII的典型示例中,吞下关闭文件时发生的任何错误:
#include <iostream>
#include <string>
#include <fstream>
#include <stdexcept>
void write_to_file (const std::string & message) {
// try to open file
std::ofstream file("example.txt");
if (!file.is_open())
throw std::runtime_error("unable to open file");
// write message to file
file << message << std::endl;
// file will be closed when leaving scope (regardless of exception)
}
Run Code Online (Sandbox Code Playgroud)
似乎没有办法确定file自动关闭时是否发生错误; 显然一个只能调用file.rdstate()而file上的范围.
我可以file.close()手动调用然后检查错误,但是我必须在从示波器返回的每个地方都这样做,这违背了RAII的目的.
有些人评论说,在析构函数中只能发生文件系统损坏等不可恢复的错误,但我不相信这是正确的,因为析构函数AFAIK在关闭文件之前会刷新文件,并且在刷新时可能会发生可恢复的错误.
那么是否有一种常见的RAII方法来获取破坏期间发生的错误?我读到从析构函数中抛出异常是危险的,这听起来不像正确的方法.
我能想到的最简单的方法是注册一个回调函数,如果在破坏期间发生任何错误,析构函数将调用该函数.令人惊讶的是,似乎没有一个事件得到支持ios_base::register_callback.这似乎是一个重大的疏忽,除非我误解了一些事情.
但也许回调是在现代课程设计中被破坏时通知错误的最常见方式?
我假设在析构函数中调用任意函数也很危险,但是将调用包装在一个try/catch块中是完全安全的.
升级 Flow 时出现错误是相当常见的node_modules,但这会使一堆错误消失:
[declarations]
<PROJECT_ROOT>/node_modules/.*
Run Code Online (Sandbox Code Playgroud)
另外,我认为它显着减少了 Flow 必须处理的数据量,因为
在声明模式下,代码不进行类型检查。然而,类型检查器在检查其他代码时会提取并使用函数、类等的签名。
但这不是默认设置。我有什么理由不应该这样做吗?如果类型签名本身有错误(例如实现接口但方法类型不同的类,或者库和使用项目之间安装的流类型定义不同),它是否会无法报告使用这些类型签名的代码中的一些错误?
我应该注意,因为 AFAIK Flow仍然没有只能从源代码*输出定义的工具,我只是将整个源文件复制到.js.flow我们的许多内部包中。因此,在使用这些包的项目中升级 Flow 时会发生错误。graphql然而,即使在我们当前使用的版本中,我也看到了错误。
*print-signature当我尝试使用文档中提到的 CLI 命令时,它实际上似乎并不存在。
我正在将遗留的PHP应用程序移植到Laravel,并且需要将各种PHP文件中定义的函数包含到Laravel控制器中.将这些文件复制到Laravel项目中并不方便,因为它们仍将用于站点的非Laravel部分,我想确保代码仍然是共享的.我如何require()在Laravel中的某个地方使用所有遗留PHP文件的相对路径?
例如,在页面顶部,我将转换为Laravel:
<?php
require("../include.php");
require_once("../../trades/trades_include.php");
require_once("account_access_page.php");
require_once("../includes/accounts.php");
Run Code Online (Sandbox Code Playgroud)
如您所见,../include.php包含具有相对路径的其他文件:
<?php
require_once("general.php");
require_once("../../config.php");
require_once("../../includes/utility.php");
require_once("../../includes/session_helper.php");
require_once("../../includes/date.php");
require_once("../../includes/form.php");
require_once("../../includes/mysql.php");
require_once("../../includes/page.php");
require_once("../../includes/table.php");
Run Code Online (Sandbox Code Playgroud)
编辑:包含文件composer.json并不能解决我的问题,因为嵌套require_once()s失败.有没有人知道解决方法?
在 Bootstrap 崩溃的代码中,在hide()方法中,我看到以下行:
this.$element[dimension](this.$element[dimension]())[0].offsetHeight
我不明白最后的意义.offsetHeight是什么,除非它有副作用,因为它没有被分配给任何东西。它有副作用吗?
我正在构建多个选择模式。当用户按下该项目时,该项目应标记为“已检查”。
问题我从 id 数组中添加/删除了 id。当我打开并检查模态时,它没有显示“检查”标志。但是当我再次关闭并打开模态时,它显示“检查”标志。
为了跟踪所选项目,我在模态组件的状态中定义了这些项目。
state = {
selectedSeasonIds: this.props.selectedSeasonIds,
}
Run Code Online (Sandbox Code Playgroud)
这是我用来在屏幕上显示模态的 react-native-modal
<Modal
isVisible={isSelectorVisible}
onBackdropPress = {() => this.props.hideSelector()}>
<View style={styles.modalContainer}>
<FlatList
style={styles.root}
data={this.props.items}
ItemSeparatorComponent={this._renderSeparator}
keyExtractor={this._keyExtractor}
renderItem={this._renderItemForMultiple}/>
</View>
</Modal>
Run Code Online (Sandbox Code Playgroud)
这是每个项目的渲染功能
_renderItemForMultiple = ({item}) => {
return (
<TouchableOpacity
style={styles.itemStyle}
onPress={() => {this._handleMultipleItemPress(item.id)}}>
<RkText>{item.value}</RkText>
{ this._renderCheck(item.id) } <<< Here is the problem
</TouchableOpacity>
);
}
Run Code Online (Sandbox Code Playgroud)
当用户单击该项目时,FlatList 的项目调用 _handleMultipleitemPress
_handleMultipleItemPress = (id) => {
let { selectionType } = this.props;
let { selectedSeasonIds, selectedSizeIds, selectedColorIds } = this.state;
if(selectionType===2) …Run Code Online (Sandbox Code Playgroud) 我正在尝试将大多数路由渲染为AppShell包含导航栏的组件的子组件.但我想将我的404路由渲染为一个未包含的独立组件AppShell.
<Router>
<Route component={AppShell}>
<Route path="/about" component={About} />
<Route path="/" component={Home} />
</Route>
<Route path="*" component={NotFound} />
</Router>
Run Code Online (Sandbox Code Playgroud)
一切都按预期工作:
/ 呈现 <AppShell><Home /></AppShell>/about 呈现 <AppShell><About /></AppShell>/blah 呈现 <NotFound />现在我正在这样做,但问题是渲染AppShell(没有孩子,但仍然是导航栏):
const Routes = () => (
<div>
<AppShell>
<Match exactly pattern="/" component={Home} />
<Match pattern="/about" component={About} />
</AppShell>
<Miss component={NotFound} />
</div>
)
Run Code Online (Sandbox Code Playgroud)
有了这个:
/渲染<div><AppShell><Home /></AppShell></div>(好)/about渲染<div><AppShell><About /></AppShell></div>(好)/blah渲染<div><AppShell /><NotFound /></div> (问题 …javascript ×2
c++ ×1
debugging ×1
destructor ×1
dom ×1
field ×1
flowtype ×1
include ×1
java ×1
karma-runner ×1
keyword ×1
laravel ×1
methods ×1
node.js ×1
offsetheight ×1
php ×1
raii ×1
react-native ×1
react-router ×1
reflection ×1
require ×1
side-effects ×1