一位同事(他是Java的新手)今天停下来问了一个看似简单的问题.不幸的是,我做了一个非常可怕的工作,试图向他解释.他有一本书有一些看起来像这样的代码:
class XCopy {
public static void main(String[] args) {
XCopy x = new XCopy(); // 1
x.doIt();
}
public void doIt() {
// Some code...
}
}
Run Code Online (Sandbox Code Playgroud)
他在第1行感到困惑.他想知道的是为什么可以在XCopy类的定义中创建一个新的XCopy实例.他认为这会产生某种前向引用错误.毕竟,我们还没有宣布XCopy类是什么,所以我们怎么能创建一个呢?
我当然知道这是有效的代码,但是,当我试图向他解释时,我发现自己磕磕绊绊的答案,我担心他比他开始时更加困惑.我想听听其他解释为什么会这样.
有什么想法吗?为什么你可以在类的定义中实例化一个类的实例呢?
当我的应用程序进入活动状态时,我正在使用presentModalView在iPad应用程序中显示模态视图:
- (void)applicationDidBecomeActive:(UIApplication *)application {
myViewController vc = [[myViewController alloc] init];
vc.modalPresentationStyle = UIModalPresentationFormSheet;
vc.modalTransistionStyle = UImdoalTransitionStyleCoverVertical;
[self.window.rootViewController presentModalViewController:vc animated:YES];
}
Run Code Online (Sandbox Code Playgroud)
它运行正常,但myViewController只有320 X 340,但它显示为一个更大的视图.在使用presentModalViewController时,无论如何都要自定义或覆盖视图大小?或者除了presentModalViewController之外还有其他方式来显示模态视图吗?
我正在使用GNU Emacs 22.2.1和cperl 5.23.
我有这样的perl代码:
sub foo
{
if($x)
{
print "x";
}
else
{
print "y";
}
}
Run Code Online (Sandbox Code Playgroud)
我想将代码重新加入2空格缩进.但是,当我运行cperl-indent-region此代码时,我得到:
sub foo
{
if ($x) {
print "x";
} else {
print "y";
}
}
Run Code Online (Sandbox Code Playgroud)
我正在创建一个带有服务层(WCF网站)和Silverlight 4客户端的应用程序.RIA服务不是一种选择,因此我们创建了来回传递的中间类.出于这个问题的目的,让我们假设我来回传递美味Food物体.
public class FoodData
{
public int Id { get; set; }
public string Name { get; set; }
public Tastyness TastyLevel { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
EF模型本质上是同一个类,一个包含三个基本字段的表(Tastyness是一个与我们的enum Tastyness相对应的int).
在进行实体框架查询时,我发现自己经常使用这种语句:
public List<FoodData> GetDeliciousFoods()
{
var deliciousFoods = entities.Foods
.Where(f => f.Tastyness == (int)Tastyness.Delicious)
.ToList() // Necessary? And if so, best performance with List, Array, other?
.Select(dFood => dFood.ToFoodData())
.ToList();
return deliciousFoods;
}
Run Code Online (Sandbox Code Playgroud)
没有.ToList()调用,我得到一个关于LINQ无法将自定义方法转换为查询等价物的异常,我理解.
我的问题是在.Select(... )之前调用.ToList(),使用自定义扩展将我们的对象转换为Food对象的POCO版本.
有没有更好的模式在这里做,或者甚至可能是更好的替代.ToList()可能更高效,因为我并不真正需要List <..>结果的功能.
是否有任何python库可以让我绘制z = f(x,y),其中z表示为密集光栅化图像中的颜色(与一堆散点图的颜色相对)?如果是这样,我会使用什么功能?
看起来matplotlib.pyplot中的一些轮廓函数接近我想要的,但它们绘制轮廓线,我不希望这样.
我有一个我需要验证的正则表达式.正则表达式中有双引号,但我似乎无法弄清楚如何正确地逃避它们.
第一次尝试,不起作用,因为引号不会被转义.
while read line
do
if [[ $line =~ "<a href="(.+)">HTTP</a>" ]]; then
SOURCE=${BASH_REMATCH[1]}
break
fi
done < tmp/source.html
echo "{$SOURCE}" #output = {"link.html"} (with double quotes)
Run Code Online (Sandbox Code Playgroud)
我怎样才能正确运行这个输出是没有双引号的link.html.
我试过了...
while read line
do
if [[ $line =~ "<a href=/"(.+)/">HTTP</a>" ]]; then
SOURCE=${BASH_REMATCH[1]}
break
fi
done < tmp/source.html
echo "{$SOURCE}" #output = {}
Run Code Online (Sandbox Code Playgroud)
没有运气.有人可以帮助我,这样我就可以不再在我的桌子上敲打头了吗?我对Bash不太满意.谢谢!
有人可以解释这个代码不正确的地方吗
<script>
chrome.browserAction.onClicked.addListener(function(window) {
chrome.windows.onCreated.addListener(function(enumerated string ["popup"]) {
chrome.windows.create({'url': chrome.extension.getURL('redirect.html')}, function(window) {
});
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
我正在尝试实现这一点,当在新的弹出窗口上单击扩展时将加载.
我有数据作为方阵.我想meshgrid在Matlab(带有颜色渐变的山脉)中绘制它.此外,如果有一个大悬崖,我想标记它.如下所示的东西

我的数据是
_92765 _222156 _384259 _384249 _384247 _384250
_92765 -1 3.4 4.85106 8.12927 8.462 9.12643
_222156 3.4 -1 1.50877 3.66383 3.58554 3.69655
_384259 4.85106 1.50877 -1 4.48433 4.51367 4.14421
_384249 8.12927 3.66383 4.48433 -1 0.288 0.252
_384247 8.462 3.58554 4.51367 0.288 -1 0.196
_384250 9.12643 3.69655 4.14421 0.252 0.196 -1
Run Code Online (Sandbox Code Playgroud)
我该怎么办呢?谢谢
我在C中使用libpng编写了一个小实用程序.在linux下,我只需安装libpng-dev并执行"gcc myapp.c /usr/lib/libpng.so -o myapp".在Mac OS X中,我安装了Xcode工具,我相信它包含了libpng.我链接了什么,是否需要为png.h指定包含路径?
我一直试图解决这个问题,并试图遵循任何建议,但在用户按下电影播放器上的"完成"后,我似乎无法让'MPMoviePlayerPlaybackDidFinishNotification'工作.
- (void)myMovieFinishedCallback:(NSNotification*)aNotification {
MPMoviePlayerController* theMovie=[aNotification object];
[[NSNotificationCenter defaultCenter] removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:theMovie];
[theMovie pause];
[theMovie stop];
[theMovie autorelease];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
}
- (void)myMovieViewFinishedCallback:(NSNotification*)aNotification {
MPMoviePlayerViewController* theMovieView=[aNotification object];
[self dismissMoviePlayerViewControllerAnimated];
[[NSNotificationCenter defaultCenter]removeObserver:self name:MPMoviePlayerPlaybackDidFinishNotification object:theMovieView];
[theMovieView pause];
[theMovieView stop];
[theMovieView autorelease];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
}
- (IBAction)safetyVideo:(id)sender {
NSString *path = [[NSBundle mainBundle] pathForResource:@"Ball_Crunch" ofType:@"m4v"];
if ([[[UIDevice currentDevice] systemVersion] doubleValue] >= 3.2) {
MPMoviePlayerViewController*tmpMoviePlayViewController=[[[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL fileURLWithPath:path]] retain];
if (tmpMoviePlayViewController) {
[self presentMoviePlayerViewControllerAnimated:tmpMoviePlayViewController];
tmpMoviePlayViewController.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
[[NSNotificationCenter defaultCenter] addObserver:self …Run Code Online (Sandbox Code Playgroud) bash ×1
c ×1
conditional ×1
cperl-mode ×1
emacs ×1
ggplot2 ×1
java ×1
libpng ×1
linker ×1
linq ×1
linq-to-sql ×1
macos ×1
matplotlib ×1
modal-dialog ×1
objective-c ×1
perl ×1
plot ×1
python ×1
r ×1
regex ×1
view ×1
xcode ×1