我怎样才能将一个arugument传递给听众方法?
我试过这样的:
<p:poll interval="3" listener="#{vehicleController.onPoll('12')}"
update="vehicleDataList"/>
Run Code Online (Sandbox Code Playgroud)
和
<p:poll interval="3" listener="#{vehicleController.onPoll(vehicle.vehicleLicense)}"
update="vehicleDataList"/>
Run Code Online (Sandbox Code Playgroud)
但它抛出以下异常:
javax.servlet.ServletException: /monitorVehicles/vehiclesList.xhtml
Failed to parse the expression [#{vehicleController.onPoll('12')}]
Run Code Online (Sandbox Code Playgroud)
我怎么能得到这个?
我在Ruby中有两种方法:
def reverse(first,second)
@items[first..second]=@items[first..second].reverse
end
Run Code Online (Sandbox Code Playgroud)
和:
def reverse
@items.reverse!
end
Run Code Online (Sandbox Code Playgroud)
我可以将这些功能组合成一个功能并使用一个if first.nil? && second.nil?条件,或者最好保持它的状态吗?
我在书中看到如何将特定的排序函数传递给Python自己的内置sorted()函数,如下所示:
def mysort(a, b):
if a[3] < b[3]:
return -1
elif a[3] > b[3]:
return 1
else:
return 0
data = [
('Alpha Centauri A', 4.3, 0.26, 1.56),
('Alpha Centauri B', 4.3, 0.077, 0.45),
('Alpha Centauri C', 4.2, 0.00001, 0.00006),
("Barnard's Star", 6.0, 0.00004, 0.0005),
('Wolf 359', 7.7, 0.000001, 0.00002),
('BD +36 degrees 2147', 8.2, 0.0003, 0.006),
('Luyten 726-8 A', 8.4, 0.000003, 0.00006),
('Luyten 726-8 B', 8.4, 0.000002, 0.00004),
('Sirius A', 8.6, 1.00, 23.6),
('Sirius B', 8.6, 0.001, 0.003),
('Ross …Run Code Online (Sandbox Code Playgroud) printf没有引号的数字参数有什么作用?
例如printf( 3 + "goodbye");导致输出dbye.为什么我得到这个输出?
什么是(void)sender;在下面的代码呢?我无法理解该表达式的用途.
- (IBAction)signIn:(id)sender {
(void)sender;
[self dismissKeyboardIfNeeded];
}
Run Code Online (Sandbox Code Playgroud) 关于"我什么时候使用引用和什么时候指针?"有很多问题.他们让我有点困惑.我认为引用不会占用任何内存,因为它只是地址.
现在我做了一个简单的Date课程,向他们展示了代码审查社区.他们告诉我不要在以下示例中使用该引用.但为什么?
有人告诉我,它将分配指针所分配的相同内存.这与我学到的相反.
class A{
int a;
public:
void setA(const int& b) { a = b; } /* Bad! - But why?*/
};
class B{
int b;
public:
void setB(int c) { b = c; } /* They told me to do this */
};
Run Code Online (Sandbox Code Playgroud)
那么我什么时候在参数中使用引用或指针,何时只是一个简单的副本?在我的例子中没有引用,常量是不必要的吗?
我有以下枚举:
public enum Months {
JAN(31),
FEB(28),
MAR(31),
APR(30),
MAY(31),
JUN(30),
JUL(31),
AUG(31),
SEP(30),
OCT(31),
NOV(30),
DEC(31);
private final byte DAYS; //days in the month
private Months(byte numberOfDays){
this.DAYS = numberOfDays;
}//end constructor
public byte getDays(){
return this.Days;
}//end method getDays
}//end enum Months
Run Code Online (Sandbox Code Playgroud)
它给了我一个错误,说"构造函数Months(int)是未定义的",虽然我传递了一个有效的字节参数.我究竟做错了什么?
这是使用弱参数的一个小例子:
@interface MYTestObject : NSObject
@end
@implementation MYTestObject {
void(^_block)(void);
}
- (void)dealloc {
NSLog(@"DEALLOC!");
}
- (id)init {
if (self = [super init]) {
[self doSomethingWithObject:self];
}
return self;
}
- (void)doSomethingWithObject:(id __weak /* <- weak argument! */)obj {
_block = ^{
NSLog(@"%p", obj);
};
}
@end
Run Code Online (Sandbox Code Playgroud)
它有效:-dealloc被称为!此外,如果你删除__weak你将获得一个保留周期,这是绝对正确的.
不知道,如果这只是一个副作用,使用弱论点是完全不安全的吗?或者它是一个特定的行为,我只是一个糟糕的谷歌用户?
arguments weak-references objective-c automatic-ref-counting
Run Code Online (Sandbox Code Playgroud)** Reason for termination = ** {badarg,[{erlang,'++',[<<>>,"</after></set></query></iq>"]}, {geoloc,get_nearby,1},
方法是:
get_nearby({_Pid, DynVars})->
%Last = ts_dynvars:lookup(last, DynVars),
Last = lists:keysearch(last,1,DynVars),
{ok, Rad} = ts_dynvars:lookup(rad,DynVars),
{ok, Lat} = ts_dynvars:lookup(lat,DynVars),
{ok, Lon} = ts_dynvars:lookup(lon,DynVars),
if is_tuple(Last) ->
{value,{Key,After}} = Last,
if length(After) == 0 ->
After2 = "0";
true ->
After2 = After
end,
"<iq id=\"" ++ common:get_random_string(5,"abcdefghijklmnopqrstuvwxyz0123456789-+=") ++ "\" xmlns=\"http://xmpp.xgate.com.hk/plugins\" to=\"xmpp.xgate.hk.com\" type=\"get\"><query xmlns=\"jabber:iq:geoloc\"><geoloc><lat>" ++ Lat ++ "</lat><lon>" ++ Lon ++ "</lon><radius>" ++ Rad ++ "</radius></geoloc><set xmlns=\"http://jabber.org/protocol/rsm\"><max>" ++ integer_to_list(ran_max()) ++ "</max><after>" ++ After2 ++ …Run Code Online (Sandbox Code Playgroud) 为什么当我的溢出计算是printf()函数的参数时,float不会溢出,但是当编码计算被分配给一个单独的变量float_overflowed,并且不是printf函数的参数时,我得到了'inf'的预期结果?为什么会这样?是什么造成了这种差异?
导致我回答这个问题的代码和结果如下.
这是我的代码,当计算是一个参数时,它没有按预期执行:
float float_overflow;
float_overflow=3.4e38;
printf("This demonstrates floating data type overflow. We should get an \'inf\' value.\n%e*10=%e.\n\n",float_overflow, float_overflow*10); //No overflow?
Run Code Online (Sandbox Code Playgroud)
结果:
This demonstrates floating data type overflow. We should get an 'inf' value.
3.400000e+38*10=3.400000e+39.
Run Code Online (Sandbox Code Playgroud)
而且,当计算不是一个论点时:
float float_upperlimit;
float float_overflowed;
float_upperlimit=3.4e38;
float_overflowed=float_upperlimit*10;
printf("This demonstrates floating data type overflow. We should get an \'inf\' value.\n%e*10=%e.\n\n",float_upperlimit, float_overflowed); //for float overflow
Run Code Online (Sandbox Code Playgroud)
及其结果:
This demonstrates floating data type overflow. We should get an 'inf' value.
3.400000e+38*10=inf.
Run Code Online (Sandbox Code Playgroud)