问题列表 - 第47023页

在这种情况下,可以替代instanceof方法

您好,我想知道有什么比这更优雅的替代品:

class Base...

class A extends Base...

class B extends Base...

//iterator of colection containing mixed As and Bs i want to remowe Bs and do omething with As
while(iterator.hasNext()) {
    Base next = iterator.next();
    if(next instanceof A) // do something
    if(next instanceof B)
        iterator.remove();
}
Run Code Online (Sandbox Code Playgroud)

播种替代品...

谢谢你的建议。

编辑:基类可能有许多子类,而不仅仅是两个,它们的数量可能会随着时间增长

java instanceof

5
推荐指数
1
解决办法
6121
查看次数

什么是布尔?返回类型意味着什

我看到一个方法返回bool?,有没有人知道它的含义?

.net c#

11
推荐指数
3
解决办法
1万
查看次数

通过在 qt gui 应用程序中单击按钮启动新表单?

我正在尝试一些简单的应用程序。我想知道如何通过单击主窗口中的按钮来启动新表单。请用一个简单的例子向我解释一下。

forms user-interface qt widget button

6
推荐指数
1
解决办法
2万
查看次数

如何将项添加到numpy数组中

我需要完成以下任务:

从:

a = array([[1,3,4],[1,2,3]...[1,2,1]])
Run Code Online (Sandbox Code Playgroud)

(向每行添加一个元素):

a = array([[1,3,4,x],[1,2,3,x]...[1,2,1,x]])
Run Code Online (Sandbox Code Playgroud)

我试过像[n] =数组([1,3,4,x])这样的东西

但numpy抱怨形状不匹配.我尝试迭代a并将元素x附加到每个项目,但不会反映更改.

有关如何实现这一目标的任何想法?

python numpy

69
推荐指数
3
解决办法
21万
查看次数

在PHP中调整PNG图像的大小

我在调整PNG大小时没有显示图像,但以下代码适用于JPEG.

list($width_orig, $height_orig) = getimagesize( $fileName );

$ratio_orig = $width_orig/$height_orig;

if ($width/$height > $ratio_orig) {
   $width = $height*$ratio_orig;
} else {
   $height = $width/$ratio_orig;
}

// Resample
$image_p = imagecreatetruecolor($width, $height);

if( $type )){
    switch( $type ){
        case 'image/jpeg':
            $image = imagecreatefromjpeg($fileName);
            imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
            imagejpeg($image_p, null, 100);
        break;

        case 'image/png':
            imagealphablending( $image_p, false );
            imagesavealpha( $image_p, true );
            $image = imagecreatefrompng( $fileName );
            imagecopyresampled( $image_p, $image, 0, 0, 0, 0, $width, $height, …
Run Code Online (Sandbox Code Playgroud)

php png gd resize

12
推荐指数
2
解决办法
2万
查看次数

如何使用粘贴将变量添加到数据框?

我有一组R对象,c1,c2,c3,...,c10每个对象都有相同的长度,并喜欢从这些对象形成一个数据帧.我可以做到df<-data.frame(c1,c2,c3,c4,c5,c6,c7,c8,c9,c10).有没有更有效的方法来做到这一点,也许使用paste

谢谢你的帮助.

r paste dataframe

1
推荐指数
1
解决办法
582
查看次数

内存问题/ overrelease with navigationcontroller和包含子CALayer的视图

我在周末期间未能解决这个问题...我认为对Objective-C内存管理有很好的了解,但是这个很难解决.

总结一下上下文:我有一个吸引人的UIViewController,我在我的navigationcontroller中推送.这个UIViewController包含一个UIScrollView(在IB中创建).在UIViewController viewDidLoad()函数中,我添加了一个背景PDF(在UIview层的CATiledLayer子层中).

问题是,当我从导航控制器弹出UIViewController时,应用程序崩溃了.

使用Zombies工具和NSZombieLevel表明这是因为UIViewController被过度释放.

这是UIViewController:

@interface PlanViewController : UIViewController <UIScrollViewDelegate> {
    UIScrollView *panelScrollView;
    UIView *myContentView;
    CGPDFDocumentRef myDocumentRef;
    CGPDFPageRef myPageRef;
}

@property (nonatomic, retain) IBOutlet UIScrollView *panelScrollView;
@property (nonatomic, retain) UIView *myContentView;

@end

@implementation PlanViewController
@synthesize panelScrollView;
@synthesize myContentView;

- (void)viewDidLoad {
    [self setTitle:@"Plan"];

    myDocumentRef = CGPDFDocumentCreateWithURL((CFURLRef)[[NSBundle mainBundle] URLForResource:@"salonMap" withExtension:@"pdf"]);
    myPageRef = CGPDFDocumentGetPage(myDocumentRef, 1);
    CGRect pageRect = CGRectIntegral(CGPDFPageGetBoxRect(myPageRef, kCGPDFCropBox));

    CATiledLayer *tiledLayer = [[CATiledLayer alloc] init];
    [tiledLayer setDelegate:self];
    [tiledLayer setTileSize:CGSizeMake(1024.0, 1024.0)];
    [tiledLayer setLevelsOfDetail:4];
    [tiledLayer setLevelsOfDetailBias:8];
    [tiledLayer setFrame:pageRect]; …
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch memory-management release-management uinavigationcontroller

4
推荐指数
1
解决办法
1178
查看次数

确定一些向量的差异

我想区分数据向量以找到相似的数据向量.例如:

A=[4,5,6,7,8];
B=[4,5,6,6,8];
C=[4,5,6,7,7];

D=[1,2,3,9,9];
E=[1,2,3,9,8];
Run Code Online (Sandbox Code Playgroud)

在前面的例子中,我想区分A,B,C向量彼此相似(不相同),D,E彼此相似.结果应该类似于:A,B,C相似且D,E相似,但A,B,C组与D,E组不相似.Matlab可以做到这一点吗?我正在考虑使用一些分类算法或Kmeans,ROC等.但我不确定哪一个是最好的.

有什么建议吗?提前致谢

math matlab classification vector

6
推荐指数
2
解决办法
183
查看次数

集合<E>和集合<E>是一样的吗?

我对Java中的这两个接口有疑问.设置扩展集合,但不添加任何内容.它们完全一样.我在这里错过了什么吗?

java collections interface set

4
推荐指数
3
解决办法
282
查看次数

定义字符串数组

我想定义一个像这样的字符串数组:

#define sup (const char**) ("string1", "string2")
Run Code Online (Sandbox Code Playgroud)

但是当我尝试打印第一个字符串时它失败了:

printf("The string: %s\n",sup[0]); 
Run Code Online (Sandbox Code Playgroud)

怎么以正确的方式做到这一点?

c arrays string c-preprocessor

3
推荐指数
1
解决办法
2万
查看次数