关于Warning “Multiple markers at this line – The type is deprecated”的解释

时间:13-02-27 栏目:android学习笔记 作者:鲁智森也有文化 评论:0 点击: 12,684 次


I  am using an AbsoluteLayout for a Activity and have it defined in a xml file.

I added this line of code because I am trying to add a list of buttons dynamically and I get the following warning.

private AbsoluteLayout layout = (AbsoluteLayout) findViewById(R.id.viewsaved);
Warning:The type AbsoluteLayout is deprecated

The code still appears to work properly, but I was just curious to see if anyone knows why this warning appears?

翻译:我写了上述的一段代码,eclipse提示,类型AbsoluteLayout 是不赞成使用的,但是代码跑起来没有什么问题,为什么,这是什么状况?



It appears because it is deprecated. You should not use AbsoluteLayout anyway, it was deprecated for a good reason.

Deprecated code is code that is still in the release for backwards compatibility reasons (ie for old programs to use) but has been superceeded by a newer and better peice of code.

In most Java libraries, especially the very popular ones, the maintainers try very hard to make sure if you make code against an old version of the library that it won't break with a newer version (backward compatability.)

However, sometimes they realize they have made mistakes that are fundamental to the library in general and cannot be fixed. In this case, they deprecate. It means "yes it will work exactly like it did before, but be warned: there is a serious flaw in it." Typically, they follow this up with a suggested replacement.

In a related note, while I haven't done Android, I have done a lot of Java gui development. It's so tempting to say "I'll just use absolute positioning. I have no problem keeping track of everything." But as your program grows, sure enough it gets so difficult to keep it all in check. Only now, you have tons of code that has to be refactored to change it into a more maintainable layout. Don't fall into that trap: use a good layout manager from the start!

-- Explained by corsiKa (Apr 28 '11 at 23:19  )

翻译:In short , 编译环境不建议使用这个函数,一般是sdk或者lib有新的版本有新的替换函数 效率上更好或者修复了某些bug,但是老的函数还是能用只要是保证后向兼容而存在但是不建议使用了。可以通过添加 @SuppressWarnings("deprecation")消除。

关于Warning “Multiple markers at this line – The type is deprecated”的解释:等您坐沙发呢!